I want to show a button at the end of an Android list view. How can I achieve this?
I don\'t want to stick it to the activity bottom using alignparentbottom=
Simply Provide "layout_weight = 1" of ListView.
Example :
<?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">
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:cacheColorHint="#ff6a00"
android:divider="#ff8f40"
android:layout_weight="1"
android:dividerHeight="1px" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#ff8f40"
android:padding="20dp"
android:text="Click"
android:textColor="#FFFFFF"
android:textSize="22sp"
/>
</LinearLayout>
I do it like this fixed button at the buttom of the screen
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/btn_New" >
</ListView>
<Button
android:id="@+id/btn_New"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:text="@string/New"
android:width="170dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
if ur using linearLayout then assign android:layout_weight="1" to the listview and dont assign weight for button it works
You could do something like this:
final Button btnAddMore = new Button(this);
btnAddMore.setText(R.string.art_btn_moreIssues);
exArticlesList = (ExpandableListView) this.findViewById(R.id.art_list_exlist);
exArticlesList.addFooterView(btnAddMore);