I'm trying to code a dialogFragment which contains a ListView and a button below that ListView. The button must be always visible, this means that you can scroll the ListView but the button remains always visible.
The Dialog must also adapt its height. That means that if the listView contains only fews elements (1 or 2 elements) the DialogFragment should not fill the entire height of the screen...
This is my code:
<?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="wrap_content">
<LinearLayout
android:orientation="vertical"
android:padding="@dimen/fragment_default_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/Back_arrow"
android:id="@+id/imgBack" />
<TextView
android:text="@string/this_pizzeria_require_a_phone_number_inorderto_accept_orders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/default_title" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edtPhoneNumber"
android:layout_marginBottom="4dp"
android:singleLine="true"
android:imeOptions="actionDone"
android:hint="@string/choose_from_the_below_list_or_insert_a_new_one_here"
android:inputType="phone" />
<ListView
android:id="@+id/lvPhones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnAdd"
android:dividerHeight="1dp" />
<Button
android:id="@+id/btnDone"
android:text="@string/done"
style="@style/default_button" />
</LinearLayout>
</RelativeLayout>
This code works fine, but if the listView contains a lot of items, the button below disappear.
This is a screen of the dialog:
As you can see the button is stretched, and adding another item to the listView, it disappears.
Is there a way to achieve my goal?
Thanks a lot!