Listview在iOS上滚动而不在Android上滚动

问题描述 投票:0回答:1

在iOS上运行良好,但在Android上无法滚动。您能检查一下我做错了什么吗,或者有什么想法可能导致这种情况,或者检查什么吗?我试图添加scrollview,添加heightRequest,并将verticalOptions更改为FillAndExpand,但似乎无济于事

<ContentView.Content>
        <AbsoluteLayout Margin="0,0,30,0">
            <Entry
                x:Name="searchBar"
                AbsoluteLayout.LayoutBounds="0,0,1,AutoSize"
                AbsoluteLayout.LayoutFlags="WidthProportional"
                BackgroundColor="White"
                HeightRequest="40"
                Placeholder="Enter sensor"
                TextChanged="SearchBar_OnTextChanged"
                TextColor="{DynamicResource RelogixDarkGray}"
                VerticalOptions="Center" />
            <ListView
                x:Name="dataListView"
                AbsoluteLayout.LayoutBounds="5,40,.98,.4"
                AbsoluteLayout.LayoutFlags="SizeProportional"
                BackgroundColor="White"
                CachingStrategy="RecycleElement"
                HasUnevenRows="True"
                IsVisible="False"
                ItemTapped="ListView_OnItemTapped">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>

                            <StackLayout Margin="5" Padding="0">
                                <Label
                                    BackgroundColor="White"
                                    FontFamily="{StaticResource NormalFont}"
                                    FontSize="16"
                                    Text="{Binding .}"
                                    TextColor="#FF464859"
                                    VerticalOptions="Center"
                                    VerticalTextAlignment="Center" />
                            </StackLayout>

                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </AbsoluteLayout>
xamarin.forms xamarin.android xamarin.ios
1个回答
0
投票

首先,我不了解TextColor="{DynamicResource RelogixDarkGray}"FontFamily="{StaticResource NormalFont}"的用途,所以我将其删除以进行测试。

然后,在IsVisible="False"中设置ListView,如果将值设置为false,则无法看到它,当您运行它时,我将其设置为False。

并且,您没有为列表视图设置ItemsSource="{Binding myModels}"。这是我的布局代码。

<AbsoluteLayout Margin="0,0,30,0">
                <Entry
                x:Name="searchBar"
                AbsoluteLayout.LayoutBounds="0,0,1,AutoSize"
                AbsoluteLayout.LayoutFlags="WidthProportional"
                BackgroundColor="White"
                HeightRequest="40"
                Placeholder="Enter sensor"
                TextChanged="searchBar_TextChanged"

                VerticalOptions="Center" />
                <ListView
                    ItemsSource="{Binding myModels}"
                x:Name="dataListView"
                AbsoluteLayout.LayoutBounds="5,40,.98,.4"
                AbsoluteLayout.LayoutFlags="SizeProportional"
                BackgroundColor="White"
                CachingStrategy="RecycleElement"
                HasUnevenRows="True"
                IsVisible="True"
                ItemTapped="dataListView_ItemTapped">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <StackLayout Margin="5" Padding="0">
                                    <Label
                                    BackgroundColor="White"

                                    FontSize="16"
                                    Text="{Binding .}"
                                    TextColor="#FF464859"
                                    VerticalOptions="Center"
                                    VerticalTextAlignment="Center" />
                                </StackLayout>

                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </AbsoluteLayout>

我注意到您使用了MVVM,您应该像这样简单地在布局背景代码中添加BindingContext = new MyModelView();

  public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            BindingContext = new MyModelView();
        } 
}

这里是MyModelView.cs

    public class MyModelView
    {
        public ObservableCollection<MyModel> myModels { get; set; }
        public MyModelView()
        {

            myModels = new ObservableCollection<MyModel>();
            myModels.Add(new MyModel() { Prop0="xxx",Prop1="xxx1",Prop2="xxxx2",Prop3=true,Prop4="xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
            myModels.Add(new MyModel() { Prop0 = "xxx", Prop1 = "xxx1", Prop2 = "xxxx2", Prop3 = true, Prop4 = "xxxx4" });
        }
    }

这里是MyModel.cs

    public class MyModel
    {
        public string Prop0 { get; set; }
        public string Prop1 { get; set; }
        public string Prop2 { get; set; }
        public bool Prop3 { get; set; }
        public string Prop4 { get; set; }
    }

这里正在运行GIF。

enter image description here

如果我为Label设置绑定值

<Label
                                    BackgroundColor="White"

                                    FontSize="16"
                                    Text="{Binding Prop0}"
                                    TextColor="#FF464859"
                                    VerticalOptions="Center"
                                    VerticalTextAlignment="Center" />

这里正在运行GIF。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.