gpt4 book ai didi

Xamarin Forms ListView 行高不正确

转载 作者:行者123 更新时间:2023-12-02 18:30:10 24 4
gpt4 key购买 nike

我一直在尝试解决在 Xamarin Forms (iOS) 中渲染 ListView 时计算的行高问题

这是我的 XAML

<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout Orientation="Vertical" Grid.Row="0">
<Label Text="{Binding Path=Name}" FontSize="18" />
<Label Text="{Binding Path=Teaser}" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Column="1" Grid.Row="0">
<Image Source="{Binding Path=ImageUrl}" WidthRequest="100" Aspect="AspectFill"
HeightRequest="100" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>

但这是它如何在模拟器中渲染的屏幕截图

(我绑定(bind)到 10 行相同的数据,这就是为什么每一行看起来都一样)

enter image description here

如您所见,行内容的行高未正确计算。

我可以为 ListView 设置固定的 RowHeight,但这并不好,因为不同设备的 rowheight 需要不同。

有人可以帮忙吗?

最佳答案

设置

your_list.HasUnevenRows = true; 

和/或

your_list.RowHeight = 60; 

关于Xamarin Forms ListView 行高不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36922541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com