gpt4 book ai didi

Xamarin iOS 图像在网格内重叠

转载 作者:行者123 更新时间:2023-12-04 12:39:07 27 4
gpt4 key购买 nike

嘿嘿

所以在 Xamarin 我有一个 <Grid><Image>和一对<Label> s 在里面,全部包裹在 <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

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

enter image description here

最佳答案

想通了 - 与我的 RowDefinitions 有关全部设置为 Auto
这让它看起来恰到好处:

<RowDefinition Height="1*" />
<RowDefinition Height="0.18*" />
<RowDefinition Height="0.77*" />

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

关于Xamarin iOS 图像在网格内重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52063059/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com