多层ExpandableListView [英] Multi-layered ExpandableListView

查看:265
本文介绍了多层ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个项目中,我需要的东西如下所示:

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)
  - ...

目前最这将是一个 ExpandableListView 内的 ExpandableListView 内的 ExpandableListView - 所以3层 ExpandableListView

At most it would be an ExpandableListView inside an ExpandableListView inside an ExpandableListView - so 3 layers of ExpandableListView:

  • MainGroup 只会持有其他 ExpandableListView
  • 亚组将持有其他 ExpandableListView 除了最后两个,这将永诺只是 ChildViews 。 (我想这两个可能只是被与一个用于 SubSubGroup
  • SubSubGroup 将八方通持有 ChildViews
  • MainGroup would only hold other ExpandableListView.
  • SubGroup would hold other ExpandableListView except for the last two, which will allways just be ChildViews. (I'm thinking those two could just be substituted with the one for SubSubGroup)
  • SubSubGroup would allways hold ChildViews.

我的问题是,我想我不明白的是如何在 ExpandableListView 布局是儿童的基本原则。我看的例子如,但不能让我的头周围的功能。

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.

我试图简单地增加一个 ExpandableListView 作为一个孩子在另一个 - 但事情不工作内的,因为只有第一项 ExpandableListView 是可见的,如果您展开外的群体之一。我可以但是通过设置外组容器的高度手动使其足够大,以显示在内部 ExpandableListView 所有项目。是最佳的,高度的计算应当然可实时进行。

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:

  • 有人可以给我的 ExpandableListView 生命周期的解释(我的意思是instantation,再利用的意见,展开/折叠听众),包括:
    • 如何以及何时是 ExpandableListView 通知一个孩子展开/折叠?
    • 如何在 ExpandableListView 知道多少空间,让所有的孩子放入一个组容器?
    • 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?

      修改

      有关我的最后一个问题,我会注意,可以在任何地方,从1到20+ MainGroups

      For my last question I might note that there can be anywhere from 1 to 20+ MainGroups.

      推荐答案

      首先,让我推荐你<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/ExpandableListView.java?av=f">Grep$c$c现场。它的Andr​​oid SDK类的来源。感谢他们,我发现了AdapterViews的基础原则(我给你一个链接ExpandableListView,但它的更好,如果你的研究不仅是它,但它的类,父母也一样)。

      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:

      如何以及何时是一个ExpandableListView通知一个孩子   展开/折叠?

      How and when is an ExpandableListView notified that a child is expanded/collapsed?

      请参阅法<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/ExpandableListView.java#548">handleItemClick(View五,INT位置,长ID)

      如何在ExpandableListView知道多少空间,使所有   孩子放入一个组容器?

      How does the ExpandableListView know how much space to make for all children to fit into a group container?

      我没有研究这个问题提得好,但据我所知,它是由该方法requestLayout()。此外,我们发现了一个滚动视图不能嵌入到另一个滚动视图。 (这是广知的错误:把ListView控件进入滚动型或ListView到ExpandableListView)。

      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).

      多大的好处是在有使用ExpandableListView创建   以上,这一比例仅为混合在一起使用一些我自己的解决方案   LinearLayouts有的OnClickListeners?

      How much benefit is there in using the ExpandableListView to create the above, compared to just mixing together my own solution using some LinearLayouts and some OnClickListeners?

      AdapterViews更快。但是,你的建设甚至ExpandableListView太复杂。你可以使用2的解决方案。

      AdapterViews are faster. But your construction is too complex even for ExpandableListView. You may use 2 solutions.

      1. 大师 - 解决方案:如果你是专业的设计自己的 从临时视图/ ViewGroups(我的意思是,你明白的方法 requestLayout(),dispatchDraw()等),然后写你自己 GrandExpandableListAdapter有3个级别。
      2. 中等的解决方案:使用ExpandableListAdapter的第一个2平,并使用LinearLayouts的 第3级。
      1. Guru-solution: if you're professional of designing your own Views/ViewGroups from the scratch (I mean, you understand methods requestLayout(), dispatchDraw() and so on), then write your own GrandExpandableListAdapter with 3 levels.
      2. Medium-solution: use ExpandableListAdapter for first 2 levels and use LinearLayouts for 3rd level.

      这篇关于多层ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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