Xamarin表单-堆叠两个ListView [英] Xamarin Forms - Two ListViews Stacked

查看:93
本文介绍了Xamarin表单-堆叠两个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的内容页面",我想让两个ListView一起使用.我希望ListView彼此堆叠.

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

如果我将它们添加为StackPannel的一部分,则每个ListView垂直占据View的一半.但是,我希望第一个(顶部)ListView在滚动时完全展开,然后拾取第二个ListView.因此,本质上,View的高度必须是每个ListView的总高度.

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.

我可以通过1个ListView完成此操作,然后进行分组,但是在这种情况下,我需要两个单独的ListView,它们在垂直方向完全展开.

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.

完成此操作的诀窍是什么?我应该使用ScrollView元素吗?

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

推荐答案

免责声明:不建议在ScrollView中使用ListView.

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

答案:是的,请使用ScrollView,但是(在投票之前,请先阅读以下内容),您必须处理Scroll的影响(至少在iOS上).

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

Xamarin的家伙在Evolve 16应用程序中做到了这一点(来源: https://github.com/xamarinhq/app-evolve )

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 .在Android上,它与reguler Listview相同.在iOS上,它将ListView的滚动设置为false(因此,它不会干扰ScrollView).
  2. AlwaysScrollView .同样,在Android上,它只是常规的ScrollView.在iOS上,它将AlwaysBounceVertical设置为true.
  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. :)

只是要弄清楚:在ScrollView中使用ListView将使ListView在页面加载后加载整个Collection,从而在您的collection中为每个项目创建ViewCell.这意味着:如果您有一个包含40个项目的Collection,则ListView将创建40个ViewCell的实例,而CachingStrategy则无关紧要.性能下降在 Andriod 上最为明显.因此,如果您无法控制集合中的项目数,请注意,这可能会严重影响性能.

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.

这篇关于Xamarin表单-堆叠两个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆