Xamarin Forms - Two ListViews Stacked

青春壹個敷衍的年華 提交于 2019-12-25 07:28:21

问题


I have a simple Content Page that I want two ListViews to live. I want the ListViews stacked on top of each other.

If I add them as part of a StackPannel, each ListView takes up half the View vertically. However, I want the first (top) ListView to expand all the way when scrolling, then pickup the second ListView. So essentially the height of the View needs to be the height of each ListView combined.

I could accomplish this via 1 ListView and just do Grouping, but in this case I want two separate ListViews that are fully expanded vertically.

What is the trick to accomplish this? Should I be using the ScrollView element?


回答1:


Disclaimer: Using a ListView inside a ScrollView is not recommended.

Answer: Yes, use a ScrollView but (keep reading below before downvoting) you must handle the impact of your Scroll (on iOS, at least).

The guys from Xamarin did this in the Evolve 16 app (source: https://github.com/xamarinhq/app-evolve)

Basically (from my understanding), you will need to follow this steps:

  1. NonScrollableListView. On Android, it's the same as a reguler Listview. On iOS, it sets the ListView's scrolling to false (so, it won't interfere with the ScrollView).
  2. AlwaysScrollView. Again, on Android, it´s just a regular ScrollView. On iOS, it sets AlwaysBounceVertical to true.

I'm not sure if I'm clear enough. Let me know. :)

[EDIT ~ Important Notice!] Just to make it clear: Using a ListView inside a ScrollView will make the ListView load the entire Collection once the Page is loaded, creating a ViewCell for EACH ITEM in your collection. Meaning that: If you have a Collection with 40 items, the ListView will create 40 ViewCell's instances and the CachingStrategy will not matter. The performance hit is most noticeable on Andriod. So, if you don't control the number of items in your collection, be aware that it might hurt badly the performance.



来源:https://stackoverflow.com/questions/38228008/xamarin-forms-two-listviews-stacked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!