一个简单的 50 项列表足以证明使用 ListView 的合理性吗?
在 Google I/O 2010 讨论 ListView 时,他们说您可能不需要使用具有有限且合理行数的 ListView。他们指出,如果您正在处理合理数量的行,则可以将它们放在 ScrollView 中。
我很好奇人们认为“合理长度”在实践中意味着什么。
在不使用 ListView 的情况下,每行视图只有几个字符串的 50 个项目的列表是否合理布局? 12个怎么样?
我习惯在 iPhone 上使用 UITableViews 来实现大多数 UI,所以我倾向于在 Android 上使用 ListViews,但我也想知道它对于某些场景可能有点过分,而且我目前对 Android 上的性能了解非常有限。
In the Google I/O 2010 talk about ListView they say you might not need to use a ListView with a bounded and reasonable number of rows. They state if you are dealing with a reasonable number of rows it is possible to just lay them out in a ScrollView.
I'm curious what people find "reasonble length" means in practice.
Would a list of 50 items with each row's views just having a few strings be reasonable to layout without using a ListView? How about 12?
I'm used to using UITableViews on iPhone for most UI so I'm inclined to use ListViews on Android but I also want to be aware it might be overkill for some scenarios and I have a really limited understanding of perf on android presently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于超过 3 个项目,ListView 确实是最佳选择,甚至对于 2 或 3 个项目也是一个不错的选择。如果不是,您最终将编写一堆将索引转换为单个变量而不是数组、数据库行或其他数据结构的代码。
ListView is really the best option for anything over 3 items, it is a good option for even 2 or 3 items. If not you'll end up writing a bunch of code that converts indexes to individual variables instead of arrays, database rows, or other data structure.
这不仅与项目的数量有关,还与您的数据收集是否会动态更新有关。如果您知道当列表在屏幕上时您永远不会更新它并且它没有很多项目,那么 LinearLayout 就可以了。
It's not only about the number of items but also about whether or not your data collection will be dynamically updated. If you know you will never update the list while it's on screen and it doesn't have many items then a LinearLayout will do just fine.
嗯,我可以在一定程度上理解逻辑,但实际上使用
ListActivity
为例,因为您的基类使事情变得非常简单。好的,如果您有一个只有十几行文本的静态列表(每个列表“项目”一行),那么使用包含TextViews
的ScrollView
将是另一种选择但实际上,我认为使用ListViews
的适配器方法要灵活得多。不,如果每个列表项都有一些要布局的字符串,那么自定义列表项布局以及
ListView
和自定义适配器基本上是必须的。Hmmm, I can understand the logic up to a point but in reality using a
ListActivity
, for example, as your base class makes things very simple. OK, if you have a static list of only a dozen or so lines of text (one for each list 'item') then using aScrollView
containingTextViews
would be an alternative but in reality using the adapter approach toListViews
is a lot more flexible in my opinion.No, if each list item has a few strings to be laid out then custom list item layouts together with a
ListView
and a custom adapter are basically a must.