2

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

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
Prabhat
  • 2,261
  • 7
  • 46
  • 74

4 Answers4

1

@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
  • 3,452
  • 1
  • 22
  • 21
1

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
  • 2,261
  • 7
  • 46
  • 74
1

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
  • 88,392
  • 43
  • 149
  • 167
0

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
  • 3,877
  • 12
  • 36
  • 54
  • 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 Sep 30 '10 at 15:56