Button under ListView not visible in Android
For this the button and the listview should be in a same linearlayout, if all views are in relative layout, add the listview and button to a linear layout and give listview weight as 1, this worked for me.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_shipping_address"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_all"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.reallymake.android.pottery.ShippingAddressActivity">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView9"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:background="@drawable/button_shape"
android:text="@string/ok"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/btn_add_new_address"
android:orientation="vertical">
<ListView
android:id="@+id/lv_addresses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/list"
android:layout_marginTop="14dp"
android:layout_weight="1" />
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lv_addresses"
android:layout_marginTop="14dp"
android:background="@drawable/button_shape"
android:text="@string/proceed" />
</LinearLayout>
This is happening because ListView
has height set to wrap_content
, which makes it extend to accommodate all items leaving no space on the screen for the button. You can use relative layout setting the button along the bottom and then the listview to occupy the remaining space:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_alignParentBottom="true" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:layout_above="@id/button1" />
</RelativeLayout>
List view takes the full page. Try to give desired weight to the elements to your code. Use this code,
<?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" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:layout_weight="5" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
I have added this line.............. android:weight="1" .......... within the list view as below
<?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" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:weight="1"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>