Xamarin.forms Listview在iOS上滚动,但在Android上不滚动
在iOS上运行良好,但在Android上不会滚动。你能不能检查一下我做错了什么,或者有什么想法可能导致这种情况,或者检查什么? 我尝试添加scrollview,添加heightRequest,并将verticalOptions更改为FillAndExpand,但似乎没有任何效果Xamarin.forms Listview在iOS上滚动,但在Android上不滚动,xamarin.forms,xamarin.android,xamarin.ios,Xamarin.forms,Xamarin.android,Xamarin.ios,在iOS上运行良好,但在Android上不会滚动。你能不能检查一下我做错了什么,或者有什么想法可能导致这种情况,或者检查什么? 我尝试添加scrollview,添加heightRequest,并将verticalOptions更改为FillAndExpand,但似乎没有任何效果 <ContentView.Content> <AbsoluteLayout Margin="0,0,30,0"> <Entry
<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}”和fontfamine=“{StaticResource NormalFont}”
使用了什么,所以我将其删除以进行测试
然后在列表视图中设置IsVisible=“False”
,如果将该值设置为False,则无法看到该值,运行时,我将其设置为True
您没有为您的列表视图设置项资源=“{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>
这里是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" });
}
}
这里是运行GIF
如果我为标签设置绑定值
<Label
BackgroundColor="White"
FontSize="16"
Text="{Binding Prop0}"
TextColor="#FF464859"
VerticalOptions="Center"
VerticalTextAlignment="Center" />
这里是运行GIF
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; }
}
<Label
BackgroundColor="White"
FontSize="16"
Text="{Binding Prop0}"
TextColor="#FF464859"
VerticalOptions="Center"
VerticalTextAlignment="Center" />