【问题标题】:How can i set expandablelistview with linearLayout?如何使用linearLayout设置expandablelistview?
【发布时间】:2013-11-30 09:50:56
【问题描述】:

在我的 android 应用程序中,我在 tableLayout 中有一个可展开的列表视图和一个按钮,但我有一个问题,表格的宽度没有完全显示,我设置了 (android:layout_width="match_parent") 但它不起作用。另一方面,当我使用线性布局时,按钮隐藏在列表下(当我打开子列表时)。项目之间的某种重叠。我有 2 个项目。其中一个隐藏在另一个之下。我该如何解决?

我的代码是:

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

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:gravity="center_horizontal">

    <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

    </TableRow>

    <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <Button
                android:id="@+id/backup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="BackUp"
                android:clickable="true"/>

    </TableRow>

</TableLayout>
</LinearLayout>

【问题讨论】:

    标签: android android-linearlayout expandablelistview tablelayout


    【解决方案1】:

    您可以在 LinearLayout 的子项中使用属性 layout_weight。它显示了它们在屏幕上获得了多少空间,因此如果您将 layout_weight 设置为 LinearLayout 中的一个视图,则此视图将占用所有可用空间。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
        <ExpandableListView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/expandableListView" />
    
        <Button
            android:id="@+id/backup"
            android:layout_gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BackUp"
            android:clickable="true" />
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2018-08-10
      相关资源
      最近更新 更多