【问题标题】:Android - RelativeLayout with ExpandableListView in ScrollViewAndroid - 在 ScrollView 中使用 ExpandableListView 的 RelativeLayout
【发布时间】:2014-06-14 12:54:49
【问题描述】:

我对 ScrollView 中的 ExpandableListView 有疑问。我的应用中有这个布局:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >

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

    <TextView
        android:id="@+id/carType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text=" "
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TableLayout
        android:id="@+id/infoTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/carType"
        android:stretchColumns="*" >

        <TableRow>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:paddingBottom="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:text="@string/tire_replacement"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/tirereplacement"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:text="@string/add_date" />
        </TableRow>

           //...rows...

    </TableLayout>

    <ExpandableListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/infoTable" >
    </ExpandableListView>
</RelativeLayout>

看起来像这样:

但我看不到整个 ExpandableListView。只有一个组标题行可见(应该有两个),如果我展开它,我看不到孩子。如果我删除android:layout_below="@+id/infoTable,就会有整个 ExpandableListView:

你知道哪里有问题吗?

【问题讨论】:

  • 不要嵌套沿同一轴滚动的视图。您的 ScrollView 和 ExpandableListView 都垂直滚动。
  • 是的,但是您有提示如何编辑布局吗?我需要在 TableLayout 下面以某种方式 ExpandableListView...
  • 不,这真的取决于您的设计。我只是告诉你,沿同一轴滚动的嵌套滚动组件在 Android 上具有固有的不良行为,并建议不要这样做。考虑到这一点,您如何设计布局完全取决于您。

标签: android android-layout scrollview android-relativelayout expandablelistview


【解决方案1】:

也许这会对你有所帮助。将 ListView 放入 ScrollView 并根据它的项目固定 ListView 的高度 How can I put a ListView into a ScrollView without it collapsing?

【讨论】:

    【解决方案2】:
    // try this way,hope this will help you...
    <?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:orientation="vertical">
    
        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.70"
            android:fillViewport="true" >
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
    
                <TextView
                    android:id="@+id/carType"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:text=" "
                    android:textAppearance="?android:attr/textAppearanceMedium" />
    
                <TableLayout
                    android:id="@+id/infoTable"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/carType"
                    android:stretchColumns="*" >
    
                    <TableRow>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="right"
                            android:paddingBottom="5dp"
                            android:paddingRight="5dp"
                            android:paddingTop="5dp"
                            android:text="@string/tire_replacement"
                            android:textStyle="bold" />
    
                        <TextView
                            android:id="@+id/tirereplacement"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:clickable="true"
                            android:text="@string/add_date" />
                    </TableRow>
    
                    //...rows...
    
                </TableLayout>
            </RelativeLayout>
        </ScrollView>
        <ExpandableListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.30">
        </ExpandableListView>
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 2012-10-09
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      相关资源
      最近更新 更多