Xamarin iOS图像在Grid内部重叠

Oma*_*ada 7 xamarin.ios xamarin.android xamarin xamarin.forms

Heyo,

因此,在Xamarin我有一个<Grid><Image>和一对夫妇<Label>的内线吧,都包裹内<ViewCell>.这在Xamarin.Android中看起来完全没问题,但是在Xamarin.iOS中,图像与标签重叠.我不确定它的区别是什么 - 为什么它在Xamarin.Android中看起来不错但在iOS中它的全部都不稳定?

下面是我的XAML和几个模型来展示我的意思.

<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <ViewCell.View>
            <Grid>
                <Grid.ColumnDefinitions>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Image Grid.Column="0" Grid.Row="0" Aspect="AspectFill" Source="{Binding ImageOverlayEN}" />
                <Label Grid.Column="0" Grid.Row="1" VerticalTextAlignment="Start" LineBreakMode="WordWrap" Text="{Binding DynamicOfferText}" FontSize="18">
                    <Label.FontFamily>
                        <OnPlatform x:TypeArguments="x:String">
                        <OnPlatform.iOS>RobotoCondensed-Regular</OnPlatform.iOS>
                        <OnPlatform.Android>RobotoCondensed-Regular.ttf#RobotoCondensed-Regular</OnPlatform.Android>
                        <OnPlatform.WinPhone>RobotoCondensed-Regular.ttf#RobotoCondensed</OnPlatform.WinPhone>
                    </OnPlatform>
                    </Label.FontFamily>
                </Label>
                <Label Grid.Column="0" Grid.Row="2" VerticalTextAlignment="Start" LineBreakMode="WordWrap" Text="{Binding DynamicOfferDetail}" FontSize="16">
                    <Label.FontFamily>
                        <OnPlatform x:TypeArguments="x:String">
                        <OnPlatform.iOS>RobotoCondensed-Regular</OnPlatform.iOS>
                        <OnPlatform.Android>RobotoCondensed-Regular.ttf#RobotoCondensed-Regular</OnPlatform.Android>
                        <OnPlatform.WinPhone>RobotoCondensed-Regular.ttf#RobotoCondensed</OnPlatform.WinPhone>
                    </OnPlatform>
                    </Label.FontFamily>
                </Label>
                </Grid>
            </ViewCell.View>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

我尝试过设置,HeightRequest但似乎没有什么区别:

#if __IOS__
    if (viewModel.Items.Count > 0)
    {
        MyListView.HeightRequest = 300 * viewModel.Items.Count;
    }
#endif
Run Code Online (Sandbox Code Playgroud)

以下是正在发生的事情的直观表示:

在此输入图像描述

Oma*_*ada 3

想通了 - 与我做好RowDefinitions准备有关Auto

这看起来恰到好处:

<RowDefinition Height="1*" />
<RowDefinition Height="0.18*" />
<RowDefinition Height="0.77*" />
Run Code Online (Sandbox Code Playgroud)

我认为发生的事情是ListView首先渲染,行定义高度在图像完成加载之前Auto设置每行的高度,然后图像完成加载并与列表视图项目的其余部分(包括标签)重叠。这可能只是 iOS 的一个怪癖,因为 Android 在图像加载完成后计算行高(解释了为什么它在 Android 中看起来很好)