tags:

views:

66

answers:

4

HI there. This is my layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" />
    <Button android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/lv" />
</RelativeLayout>

When I run this the list view occupies full screen. What I want is list view to be full screen except button area without mentioning dp. Thanks

A: 

I guess you can do this:

write:

<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/lv" />

before:

<ListView android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" />

like this:

<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/lv" />

<ListView android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" />

but I am not sure

mnish
You can't do that. You have to have declared the listview before you can reference it. Instead, set the button as alignparentbottom, and then set the listview above it
Falmarri
A: 

@mnish is quite right except that in Android 1.5 you have to declare ids before using them.

<ListView android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" />
<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/lv" />

You can use layout_above, layout_below, layout_toLeftOf, ...

fedj
Thats true. However, since i mentioned fill_parent as height, the button isn't visible.
Prabhat
Prevent this by putting android:layout_alignParentTop="true" on your listview
fedj
+1  A: 

After trying out some possibilities I found this to be helpful

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" android:layout_above="@+id/bt"/>
    <Button android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:id="@+id/bt" android:layout_alignParentBottom="true"/>
</RelativeLayout>

Thanks all of you for answers.

Prabhat
A: 

I think a LinearLayout is more suited here.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >
    <ListView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

(Yes, wrap_content is correct on ListView's layout_height, the layout_weight="1" will ensure it expands as much as possible)

Felix