我一直试图解决在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>
但这是一个如何在模拟器中渲染的屏幕截图
(我绑定到10行相同的数据,这就是为什么每一行看起来都一样)
如您所见,行高度未正确计算行内容.
我可以为ListView设置一个固定的RowHeight,但这并不好,因为不同设备的rowheight需要不同.
有人可以帮忙吗?
解决方法
组
your_list.HasUnevenRows = true;
和/或
your_list.RowHeight = 60;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。