多层ExpandableListView
我目前正在开发一个项目,其中我需要类似以下内容:
- MainGroup 1 (Expandable)
- SubGroup 1 (Expandable)
- SubSubGroup 1 (Expandable)
- Child View
- Child View
- ...
- SubSubGroup 2 (Expandable)
- Child View
- Child View
- ...
- SubGroup 2 (Expandable)
- SubSubGroup 3 (Expandable)
- Child View
- ...
- SubSubGroup 4 (Expandable)
- Child View
- ...
- SubGroup 3 (Expandable)
- Child View
- ...
- MainGroup 2 (Expandable)
- ...
最多它是 ExpandableListView
内的 ExpandableListView
内的 ExpandableListView
> - 因此 3 层 ExpandableListView
:
MainGroup
只能容纳其他ExpandableListView
。SubGroup
将保存除最后两个之外的其他ExpandableListView
,它们始终只是ChildViews
。 (我认为这两个可以用SubSubGroup
中的一个代替)SubSubGroup
将始终保存ChildViews
。
我的问题是,我认为我无法理解 ExpandableListView 如何布局其子项的基本原则。我看过这个之类的示例,但无法理解围绕功能。
我尝试简单地添加一个 ExpandableListView
作为另一个中的子项 - 但有些东西不起作用,因为如果您展开其中一个,则只有内部 ExpandableListView
的第一项可见外层群体。不过,我可以通过手动设置外部组容器的高度,使其足够大以显示内部 ExpandableListView
中的所有项目。为了达到最佳效果,高度的计算当然应该即时完成。
因此,为了解决一些更扎实的问题:
- 有人可以给我解释一下 ExpandableListView “生命周期”(我指的是实例化、视图重用、展开/折叠侦听器),包括:
ExpandableListView
如何以及何时通知子项展开/折叠?ExpandableListView
如何知道需要为所有子项留出多少空间才能放入组容器?
- 与仅使用一些
LinearLayouts
和一些OnClickListeners
将我自己的解决方案混合在一起相比,使用ExpandableListView
创建上述内容有多少好处?
编辑
对于我的最后一个问题,我可能会注意到可以有 1 到 20 多个 MainGroups
。
I'm currently working on a project in which I need something like the following:
- MainGroup 1 (Expandable)
- SubGroup 1 (Expandable)
- SubSubGroup 1 (Expandable)
- Child View
- Child View
- ...
- SubSubGroup 2 (Expandable)
- Child View
- Child View
- ...
- SubGroup 2 (Expandable)
- SubSubGroup 3 (Expandable)
- Child View
- ...
- SubSubGroup 4 (Expandable)
- Child View
- ...
- SubGroup 3 (Expandable)
- Child View
- ...
- MainGroup 2 (Expandable)
- ...
At most it would be an ExpandableListView
inside an ExpandableListView
inside an ExpandableListView
- so 3 layers of ExpandableListView
:
MainGroup
would only hold otherExpandableListView
.SubGroup
would hold otherExpandableListView
except for the last two, which will allways just beChildViews
. (I'm thinking those two could just be substituted with the one forSubSubGroup
)SubSubGroup
would allways holdChildViews
.
My problem is that I think I fail to understand the basic principles of how the ExpandableListView
layouts it's children. I've looked at examples like this, but can't get my head around the functionality.
I've tried simply adding an ExpandableListView
as a child in another - but something doesn't work as only the first item of the inner ExpandableListView
is visible if you expand one of the outer groups. I can however by setting the height of the outer groups container manually make it big enough to show all items in the inner ExpandableListView
. To be optimal, calculation of height should of course be done on the fly.
So, to get to some more solid questions:
- Can someone give me an explanation of the
ExpandableListView
"lifecycle" (by this I mean instantation, re-use of views, expand/collapse listeners) including:- How and when is an
ExpandableListView
notified that a child is expanded/collapsed? - How does the
ExpandableListView
know how much space to make for all children to fit into a group container?
- How and when is an
- How much benefit is there in using the
ExpandableListView
to create the above, compared to just mixing together my own solution using someLinearLayouts
and someOnClickListeners
?
Edit
For my last question I might note that there can be anywhere from 1 to 20+ MainGroups
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想查看此项目。我还没有尝试过,但我想值得一试。默认的 ExpanadableListView 非常有限,最初设计为仅支持 2 个级别。您可以对其进行修改以使其支持更多级别,但它会变得混乱。
You might want to check this project out. I haven't tried it, but I guess it's worth a try. The default ExpanadableListView is quite limited, designed originally to support only 2 levels. You can hack around with it to get it to support more levels than that, but it'll get messy.
尽管这不是完整的解决方案,但它仍然是一个 3 层可扩展列表。因此,如何设计它取决于您。
这是类
,这是 xml 文件
group.xml
这是在颜色文件夹下用于更改文本颜色的,它留给您,您甚至可以更改背景以获得更好的外观。
back.xml
希望它能起作用......
Even though this is not the complete solution still its a 3 layered Expandable List. So its left to you how you style it.
here is the class
and here goes the xml file
group.xml
and this is under color folder for changing text color, its left you , you can even change the background for getting better looks.
back.xml
hope it works...
首先,让我向您推荐GrepCode 站点。它有 Android SDK 类的来源。感谢他们,我已经找到了 AdapterViews 的基本原理(我给了您 ExpandableListView 的链接,但如果您不仅研究它,而且还研究它的类父级,那就更好了)。
现在,你的问题和我的答案:
请参阅方法 handleItemClick(视图v,int位置,长id)
这个问题我没有好好研究,但据我所知,它是通过 requestLayout() 方法做出来的。我们还发现一个可滚动视图不能嵌入到另一个可滚动视图中。 (这是一个众所周知的错误:将ListView放入ScrollView或将ListView放入ExpandableListView)。
AdapterView 速度更快。但是即使对于 ExpandableListView 来说,您的构造也太复杂了。您可以使用 2 种解决方案。
从头开始视图/视图组(我的意思是,你了解方法
requestLayout()、dispatchDraw()等),然后编写自己的
GrandExpandableListAdapter 有 3 个级别。
第三级。
First of all, let me recommend you GrepCode site. It has sources of Android SDK classes. Thanks for them, I've found out base principles of AdapterViews (I gave you a link to ExpandableListView, but it's better if you research not only it, but its class-parents as well).
Now, your questions and my answers:
See method handleItemClick(View v, int position, long id)
I didn't research this question well, but as far as I know, it's made by the method requestLayout(). Also we found out that one scrollable View cannot be embedded into another scrollable View. (It's wide-known mistake: to put ListView into ScrollView or ListView into ExpandableListView).
AdapterViews are faster. But your construction is too complex even for ExpandableListView. You may use 2 solutions.
Views/ViewGroups from the scratch (I mean, you understand methods
requestLayout(), dispatchDraw() and so on), then write your own
GrandExpandableListAdapter with 3 levels.
3rd level.