开发者

Android Layout LinearLayoutProblem

I want to have a site, which contains of a vertical layout, that has a content part and a footer part. Th开发者_如何学Pythone footer part should be 20% of the height of the display height. I think that it is a very common usecase.

I have tried some ways, but was not successful in the end.

How would i implement this?

TU in advance!


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="-1">
    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="20"/>
    <LinearLayout
        android:id="@+id/body"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="60"/>
    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="20"/>
</LinearLayout>

This should give you a header and footer that take 20% of the space, with the body occupying 60%. See http://developer.android.com/reference/android/widget/LinearLayout.html#setWeightSum(float) for a simple description of what this is doing.


This is what worked for me to display a footer with ads.

<LinearLayout>
<LinearLayout xmlns:myapp="http://schemas.android.com/apk/res/com.broschb.wiiscale"
    android:layout_width="fill_parent" android:layout_marginTop="5px"
    android:layout_below="@+id/weight" android:layout_height="fill_parent"
    android:gravity="center_horizontal|bottom">

    <myFooterComponents android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>


LinearLayout, right? Just set the height of both your content and footer layouts to fill_parent, and give the content area a layout_weight of 8, and the footer a layout_weight of 2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜