Fixed Button below a scrollable ListView

后端 未结 3 1070
面向向阳花
面向向阳花 2021-01-31 09:12

I have a scrollable ListView with items (like in http://developer.android.com/resources/tutorials/views/hello-listview.html). I am using an ArrayAdapter for the ite

相关标签:
3条回答
  • 2021-01-31 09:34

    If your activity extends ListActivity then you need something like this:

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">
    
        <ListView android:id="@android:id/list"
                  android:layout_height="0dip"
                  android:layout_width="match_parent"
                  android:layout_weight="1" />
    
        <Button android:id="@+id/btn" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
    
    </LinearLayout>
    

    Notice that the listview has a layout_weight set to 1. That will keep the button fixed in its place at the bottom. Hope that helps. Good luck!

    0 讨论(0)
  • 2021-01-31 09:39

    you can use a RelativeLayout to fix the button at the bottom of your layout , and add your listView above it like this :

    <RelativeLayout android:layout_width="match_parent"
             android:layout_height="match_parent">
    
          <Button android:id="@+id/btn" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"/>
    
         <ListView 
                android:id="@android:id/list"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                   android:layout_above="@id/btn" />
    </RelativeLayout>
    
    0 讨论(0)
  • 2021-01-31 09:51

    My solution based on Houcline's solution but ListView always above Button

    <CheckBox
        android:id="@+id/chbRemoveIfUninstall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
    <ListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_above="@id/chbRemoveIfUninstall"/>
    

    0 讨论(0)
提交回复
热议问题