In my Xamarin forms application, there are multiple ListView controls inside a ScrollView. But in android the scrolling is not working for ListView. Is there any alternative solution?
-
1You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView. forums.xamarin.com/discussion/2857/listview-inside-scrollviewAkash Amin– Akash Amin2016-05-25 08:25:11 +00:00Commented May 25, 2016 at 8:25
5 Answers
You SHOULD NOT include ListViews into ScrollView as it system will confuse scrolling behavior of those two. You need to redesign your page with this in mind.
Example: 1) Use ListViews inside StackLayout 2) Use TableViews inside ScrollView
1 Comment
You can simply do with set 'NestedScrollingEnabled' property true for native side. For xamarin forms you can create a custom renderer and set 'NestedScrollingEnabled' property true
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var listView = this.Control as Android.Widget.ListView;
listView.NestedScrollingEnabled = true;
}
}
Comments
ListView implements its own scrolling that might conflict with the ScrollView.
If you need to be able to scroll both lists in the same ScrollView you could for example create custom views (instead of using cells), placing them in a StackLayout inside a ScrollView
More about ListView performance, they even explain why you shouldn't place a ListView inside a ScrollView