我一直在尝试解决在 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 行相同的数据,这就是为什么每一行看起来都一样)
如您所见,行内容的行高未正确计算。
我可以为 ListView 设置固定的 RowHeight,但这并不好,因为不同设备的 rowheight 需要不同。
有人可以帮忙吗?
最佳答案
设置
your_list.HasUnevenRows = true;
和/或
your_list.RowHeight = 60;
关于Xamarin Forms ListView 行高不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36922541/