Xamarin Forms ListView 行高不正确

标签 xamarin xamarin.ios xamarin.forms

我一直在尝试解决在 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/

相关文章:

c# - Xamarin 安卓 : typesafe FindViewById

android - 如何升级到 Android SDK 25.1.3?

c# - Xamarin XAML : Type is not found from external assembly

xamarin.ios - Monotouch 使用 ASP.NET Web Api

xaml - 在Xamarin表单TabBar中使用图标字体

ios - Xamarin.Forms 如何在 Android 和 iOS 上添加应用评​​分?

ios - 如何使分组的 ListView 标题在 iOS 中正确 float (不粘)?

ios - 关于证书的 Xamarin 推送通知问题

c# - Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser 上缺少所需的代码签名

ios - Xamarin 表格 : Have I Covered the bases on iOS Push Notifications?