开发者

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:backg开发者_JAVA百科round="@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


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


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.


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜