I have a simple fragment dialog with a listview, EditText and two button (accept and cancel).
I want my layout to look like this: Listview on top EditText right below and Buttons side by side below edittext.
Now my problem is that listview can have 0 or a 100 elements. So if I put everythis in a vertical LinearLayout and listview has a lot of elements the edittext and buttons get pushed out of view. And if I use relative layout and say that edit text is aligned parent bottom and below the listview that it looks ok for 100elements but when the listview is empty the dialog uses all of the screen space.
Here is an example of my code when using relativeLayout. Is there another way to make is so that linearLayout with id "below" is below the listview but will still be visible(if list view has a lot of items) without using alignParentBottom="true" because that is the reason the layout stretches to full screen.
<?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"
android:orientation="vertical" >
<ListView
android:id="@+id/ListViewPreNotes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom" />
<LinearLayout
android:id="@+id/below"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:padding="3dp">
<TextView
android:layout_height="@dimen/label_height"
android:layout_width="130dip"
android:text="@string/note"
android:layout_marginLeft="10dip"
android:gravity="center_vertical"
android:textSize="@dimen/text_size_large"/>
<EditText
android:id="@+id/OMnote"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:textSize="@dimen/text_size_large"
android:inputType="textNoSuggestions|textCapSentences"
android:selectAllOnFocus="true"
android:hint="@string/note"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:baselineAligned="false">
<Button
android:id="@+id/dialogButtonClose"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:text="@string/ok"
style="?android:attr/borderlessButtonStyle"
android:textStyle="bold" />
<Button
android:id="@+id/dialogButtonCancel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:text="@string/cancel"
android:textStyle="bold"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>