【问题标题】:ListView not displaying correctly on iOSListView 在 iOS 上无法正确显示
【发布时间】:2018-07-21 14:36:27
【问题描述】:

我正在编写 Xamarin 表单应用程序,该应用程序在 ListView 中显示用户 cmets。

问题是它在 Android 上可以正确显示,但在 iOS 上它是开箱即用的(如屏幕截图所示)

这些项目是在运行异步网络请求收集信息后添加的,我不知道这是否会影响它。

Android 屏幕

iOS 屏幕

我的 XAML

<local:PostListView x:Name="MessageView" HasUnevenRows="True" IsPullToRefreshEnabled="True" Refreshing="MessageView_Refreshing" SeparatorVisibility="None" BackgroundColor="#7ed6df">
    <ListView.ItemTemplate>
        <DataTemplate>
            <local:PostViewCell>
                <StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
                    <Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
                        </Image.GestureRecognizers>
                    </Image>
                    <Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
                    <StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
                        <Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
                            <Image.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
                            </Image.GestureRecognizers>
                        </Image>
                        <Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
                    </StackLayout>
                </StackLayout>
            </local:PostViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</local:PostListView>

PostViewCell.cs

using SocialNetwork.iOS.Renderers;
using SocialNetwork.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(PostViewCell), typeof(PostViewCelliOS))]
namespace SocialNetwork.iOS.Renderers
{
    public class PostViewCelliOS : ViewCellRenderer
    {

        public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
        {
            var cell = base.GetCell(item, reusableCell, tv);
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            return cell;
        }
    }
}

【问题讨论】:

  • “全都搞砸了”并不是对问题的有用描述。
  • @Jason 编辑并添加了详细信息。
  • 为每个 StackLayout 添加不同的背景颜色,以便您知道哪个有问题。另外,请尝试使用 Grid 而不是堆叠堆栈布局。
  • @RodrigoE。我认为网格不会修复它,并且在设置背景颜色时我可以看到它超出了布局
  • 你能把PostViewCell的代码贴出来吗?

标签: xaml xamarin xamarin.forms xamarin.ios


【解决方案1】:

您可以尝试创建一个 StackLayout 来包装您的内容,例如:

<local:PostViewCell>
    <StackLayout>
        <StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
            <Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
                <Image.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
                </Image.GestureRecognizers>
            </Image>
            <Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
            <StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
                <Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
                    </Image.GestureRecognizers>
                </Image>
                <Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
            </StackLayout>
        </StackLayout>
    </StackLayout>
</local:PostViewCell>

【讨论】:

    猜你喜欢
    • 2022-08-16
    • 2021-01-21
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多