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>
我尝试设置HeightRequest,但似乎没有什么区别:
#if __IOS__
if (viewmodel.Items.Count > 0)
{
MyListView.HeightRequest = 300 * viewmodel.Items.Count;
}
#endif
以下是正在发生的事情的直观表示:
解决方法
弄清楚了 – 我的RowDeFinitions都设置为Auto
这看起来恰到好处:
<RowDeFinition Height="1*" /> <RowDeFinition Height="0.18*" /> <RowDeFinition Height="0.77*" />
我认为发生的事情首先是ListView渲染,自动行定义高度设置图像加载前每行的高度,然后图像完成加载并重叠列表视图的其余项目(包括标签).这可能只是iOS的一个怪癖,因为Android在图像加载完成后计算行高(解释为什么它在Android中看起来很好)