【问题标题】:Force an ExpandableListView to move other items down强制 ExpandableListView 向下移动其他项目
【发布时间】:2012-07-10 14:11:18
【问题描述】:

我的布局是一个带有一些 TextView 和其他控件的 ScrollView 以及一个 ExpandableListView。

我想要做的是当展开 ExpandableListView 时,它下方的控件会向下移动,然后在折叠时再次移动,所有控件都会向上移动,只有 Expendables 组变为可见。

问题是当使用wrap_content 作为expandView 的高度时,它的扩展什么也不显示,只有指示器(小箭头)显示它已扩展,并且当明确使用一些数字时,例如。 200dp,expandView 的最低项未显示。 (因为同时使用了两个 Scrolling 小部件)。

这是我的简化布局。

<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText" >
    <LinearLayout>
       //some controls
    </LinearLayout>

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

        <ExpandableListView
            android:id="@+id/lstDrugs"
            android:layout_width="match_parent"

//HERE is the point that wrap_content only shows the groups header

            android:layout_height=**"wrap_content"**
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:divider="@drawable/dividergradient"
            android:dividerHeight="2dp" >
        </ExpandableListView>

        <Button
            android:id="@+id/btnAddDrug"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/lstDrugs"
            android:text="Add" />
    </RelativeLayout>
</LinearLayout>

【问题讨论】:

  • 您能先修复您发布的 XML。您的滚动视图有 2 个直接子元素。还请解释当前发生的情况。从您的问题中不清楚。
  • 我刚刚解释了有关问题的情况。这是我的 XML 的重要部分,而不是全部。
  • 好的,谢谢,这有点帮助。请将 android:fillViewport="true" 添加到您的滚动视图中,看看是否有帮助。很有可能您仍然会遇到问题。 ListViews 和 ExpandableList 视图也将是滚动视图,因此将它们嵌套在 Scrollview 中会产生问题。
  • 也尝试给您的 ExpandableListView 一个布局权重=1

标签: android android-layout layout expandablelistview


【解决方案1】:

我刚刚在this 线程中找到了我的答案。

问题在于在 ScrollView 中使用 List。要处理它,您应该使用 ScrollView 以外的布局(例如 LinearLayout),并将其他小部件添加为列表的 HeaderFooter。这将启用视图的滚动和列表的扩展。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多