xamarin.forms - Listview 在 iOS 上滚动,但不是在 Android 上滚动
问题描述
在 iOS 上运行良好,但在 Android 上无法滚动。你能检查一下我做错了什么或者有什么想法可能导致这种情况,或者要检查什么?我尝试添加滚动视图,添加 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>
解决方案
首先,我不知道你用的是什么TextColor="{DynamicResource RelogixDarkGray}"
,FontFamily="{StaticResource NormalFont}"
所以我删除它进行测试。
然后你IsVisible="False"
在你的里面设置ListView
,如果你把值设置为false,就看不到了,运行的时候我把它设置为True。
而且你没有ItemsSource="{Binding myModels}"
为你的listview
. 你应该设置它,这是我的布局代码。
<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。
如果我为Label
<Label
BackgroundColor="White"
FontSize="16"
Text="{Binding Prop0}"
TextColor="#FF464859"
VerticalOptions="Center"
VerticalTextAlignment="Center" />
这里正在运行 GIF。
推荐阅读
- reverse-engineering - 模糊命令行参数 [argv]
- java - On Upgrade 方法被调用但数据未加载
- javascript - React:在组件卸载后但在另一个组件安装之前运行异步功能
- mysql - 我需要更新现有的外键,但我不能删除它以更新它
- python - 如何在按空格键或键盘上的任何键停止定时器的地方制作定时器?
- php - Laravel:上传文件时如何在公共路径中动态创建文件夹?
- slurm - 如何提交具有不同输入文件的 slurm 作业数组
- ios - Cardlayout以编程方式向左滑动不起作用
- rest - 如何从 Databricks Rest API 读取 Qliksense 中的数据
- java - 带有静态值的 Spring Thymeleaf 表单提交