Prabhat
Prabhat

Reputation: 2263

Android fill_parent issue

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

Upvotes: 2

Views: 2865

Answers (4)

Felix
Felix

Reputation: 89566

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)

Upvotes: 1

Prabhat
Prabhat

Reputation: 2263

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.

Upvotes: 1

fedj
fedj

Reputation: 3452

@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, ...

Upvotes: 1

mnish
mnish

Reputation: 3897

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

Upvotes: 0

Related Questions