2011-01-07 10 views
0

コンテンツ部分とフッター部分を持つ垂直レイアウトのサイトが必要です。フッター部分は、表示の高さの20%にする必要があります。私はそれが非常に一般的な用途であると思います。AndroidのレイアウトLinearLayoutProblem

私はいくつかの方法を試しましたが、最終的には成功しませんでした。

どうすれば実装できますか?

TUは事前に!

答えて

0
<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> 

のlayout_weightを設定します。これは、あなたに20を取るヘッダーとフッターを与える必要があります体の60%を占める空間の%。これが何をしているのかの簡単な説明については、http://developer.android.com/reference/android/widget/LinearLayout.html#setWeightSum(floatを参照してください。

+0

内部のLinearLayoutが動作するたびにandroid:layout_height = "0dip"を追加する必要がありました。しかしそれはうまくいく。 TU! – Fesp

+0

私はそれを反映するために私の答えを更新します。乾杯! – WorkerThread

0

これは私が広告付きのフッターを表示するのに役立ちました。

<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> 
0

LinearLayout、right?ちょうどあなたのコンテンツとフッターのレイアウトfill_parent、およびコンテンツ領域8のlayout_weightを与えるために、とフッターの両方の高さに2