【问题标题】:Xamarin Forms ListView Row Height IncorrectXamarin 表单 ListView 行高不正确
【发布时间】:2016-08-23 16:22:47
【问题描述】:

我一直在尝试解决在 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;
  • 啊,非常感谢。 HasUnevenRows=true 修复了它(我假设您仅在行不均匀时将其设置为 true)。我没有设置行高,因为它需要根据设备的大小而有所不同
  • 好的,我会作为答案发布

标签: xamarin xamarin.ios xamarin.forms


【解决方案1】:

设置

your_list.HasUnevenRows = true; 

和/或

your_list.RowHeight = 60; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 2018-12-07
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    相关资源
    最近更新 更多