android - 自定义可扩展 ListView 添加按钮

标签 android android-listview expandablelistview

1 如图所示那部分是我做的。但是,我需要在这个地方之前添加一个子实体,但我找不到如何做第 2 部分。

enter image description here

XML 代码

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <ExpandableListView
        android:id="@+id/drawer_list"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:background="#858585"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent" />


    <ListView
         android:id="@+id/right_drawer"
         android:layout_width="240dp"
         android:layout_height="match_parent"
         android:layout_gravity="end"
         android:choiceMode="singleChoice"
         android:divider="@android:color/transparent"
         android:dividerHeight="0dp"
         android:background="#858585"/>

</android.support.v4.widget.DrawerLayout>

最佳答案

您可以在相对布局中添加带有属性 android:layout_alignParentBottom="true" 的布局,使其在底部对齐:

 <RelativeLayout 
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start" >

   <!-- whatever the control you want here -->
   <ExpandableListView
    android:id="@+id/drawer_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#858585"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button2" />
    </LinearLayout>

</RelativeLayout>

关于android - 自定义可扩展 ListView 添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26840981/

相关文章:

android - 如何确定 ListView fling 何时变慢

android - 如何使用 Hashmap 使 Android ListView 可点击?

java - 如何将现有 SQLite 数据库连接到 ExpandableListView?

android - 删除 arrayList 中的项目,java.lang.UnsupportedOperationException

android - 无法解析方法 getActivity()

java - Android 压缩纹理加载(缺少 GL 扩展)

android - 通过本地网络在移动设备之间进行通信

android - Robolectric 测试 ListView 在适配器中的值更改后不更新

android - 如何从 ExpandableListView 中的 child 那里获取项目?

android - 将来自多个加载器/游标的数据加载到android中的 ListView 中