如何改进多级列表中视图的折叠/展开?
好吧,为了简化事情,假设我正在做一个 CommentActivity,其中所有评论都以类似线程的方式显示。
我的意思是,选择一条评论可以折叠(和展开)其所有回复。这适用于任何级别的评论。
我尝试使用 ExplandableList 但不幸的是这只适用于 2 个级别。
现在我基本上有一个 LinearLayout,其中包含两件事:
- 折叠模式下的评论(最初设置为不可见)
- 扩展模式下的注释(可见)包含...
.... - 另一个 LinearLayout 将包含对该评论的任何回复。
这有点递归的方式...... 只需更改每个视图之间的可见性即可折叠和展开评论及其回复。它有效,但速度非常慢。从点击到实际折叠/展开的时间在 2 到 3 秒之间。我想这是因为每个评论的布局都很复杂,并不是那么简单(它们有背景、图像等),有时最多有 4 级评论。
在 ExpandableList 中,这完成得非常快。如何在多级列表中实现这种性能?
Ok, to simplify things, let's say I'm doing a CommentActivity in which all comments are displayed in a threaded-like fashion.
What I mean is that selecting a comment can collapse (and expand) all of its replies. This works for any level of the comment.
I tried using ExplandableList but unfortunately this only works for 2 levels.
Now I basically have a LinearLayout that contains 2 things:
- the comment in collapsed mode (originally set to invisible)
- the comment in expanded mode (visible) which contains...
.... - another LinearLayout which will contain any replies to that comment.
This works kind of in a recursive way...
It is just a matter of changing the visibility of each view between one and another to collapse and expand the comment and its replies. It works, but veeeery slowly. The time that passes from the click until the actual collapse/expansion is between 2 or 3 seconds. I suppose this is because of the complex layout of each commentm which is not that simple (they have backgrounds, images, etc etc), and sometimes there are up to 4 levels of comments.
In the ExpandableList this was done very fast. How can I achieve this performance in a multi-level list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 LayoutInflater 来在需要时膨胀所需的下一部分,而不是预加载所有注释。
请参阅: http://developer.android.com/reference/android/view/LayoutInflater .html
Instead of preloading all the comments, you should use a
LayoutInflater
, to inflate the required next part when it's needed.See: http://developer.android.com/reference/android/view/LayoutInflater.html