How can create a Android Layout with two layout with ListView

I can not set properly for the Android layout!

On my code the ListView fills the screen. If I change the layout_height on the ListView with a number, not good for all resolutions!

I use this code:

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/FirstLinearLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >

        <ListView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/mainListView"
            >
        </ListView>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/SecondLinearLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <TableLayout
            android:layout_marginTop="10dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">
            <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button"
            android:onClick="testButton"
            android:clickable="true"
            android:background="@drawable/search_button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:onClick="exitButton"
            android:layout_marginLeft="60dp"
            android:background="@drawable/exit_button" />
            </TableRow>
        </TableLayout>
    </LinearLayout>

</RelativeLayout>

I wish it were so:

  • list with scroll
  • two buttons (on bottom)

Where I wrong?

Thank you

Answer

You want to do it like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="1" >

<LinearLayout
    android:id="@+id/FirstLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0.9"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/mainListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>

<LinearLayout
    android:id="@+id/SecondLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.1"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:clickable="true"
        android:onClick="testButton" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="60dp"
        android:background="#000000"
        android:onClick="exitButton" />
</LinearLayout>