【问题标题】:Two ExpandableListView inside a scrollViewscrollView 内的两个 ExpandableListView
【发布时间】:2013-05-28 00:27:22
【问题描述】:

我在一个活动中有两个expandableListView,起初,我把它们放在一个LinearLayout中,但是当第一个expandableListView展开太多项目时,我看不到第二个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <ExpandableListView
        android:id="@+id/myContactELV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

    <ExpandableListView
        android:id="@+id/myGroupELV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

</LinearLayout>

第一个视图包括组 aaa、bbb、ccc,第二个视图包括 ddd、eee:

当第一个展开时,第二个是看不见的,屏幕不滚动:

所以我想把它们放在一个滚动视图中,但更糟糕的是:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ExpandableListView
            android:id="@+id/myContactELV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ExpandableListView>

        <ExpandableListView
            android:id="@+id/myGroupELV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ExpandableListView>
    </LinearLayout>

</ScrollView>

所以,当两个 expandableListview 展开时,我想清楚地看到每个项目,并且屏幕滚动。我怎样才能做到这一点?

【问题讨论】:

  • 描述使用两个ELV的原因。
  • 两个ELV应该有不同的数据源、适配器和不同的含义。这里的数据是为了简单起见,它们不是真实的。
  • 你的意思是什么不同的意思?
  • 至少回答该死的问题@MaciejGórski

标签: android scrollview expandablelistview


【解决方案1】:

// 填充视口并为每个列表分配权重,以便均匀分屏

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@android:color/white"
   android:fillViewport="true" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:weightSum="2" >

    <ExpandableListView
        android:id="@+id/myContactELV"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ExpandableListView>

    <ExpandableListView
        android:id="@+id/myGroupELV"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ExpandableListView>
</LinearLayout>

</ScrollView>

【讨论】:

  • 在滚动视图中设置属性fillViewport为真。在 Linearlayout 中,为两部分分配屏幕的权重和。我希望它会工作
【解决方案2】:

您必须分别给出每个可展开列表视图的动态高度

【讨论】:

    【解决方案3】:

    scrollView 中的两个 ExpandableListView - 我不建议这样做,因为 ExpandableListView 中的子项不会关注少数 OS 版本较低的 Android 设备。你应该重新考虑你的设计。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-16
      • 2018-09-28
      • 2014-06-14
      • 2012-10-09
      • 2011-12-06
      • 1970-01-01
      相关资源
      最近更新 更多