如何改进多级列表中视图的折叠/展开?

发布于 2024-10-04 22:54:47 字数 478 浏览 3 评论 0原文

好吧,为了简化事情,假设我正在做一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2024-10-11 22:54:47

您应该使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文