我想有一個網站,其中包含一個垂直佈局,有一個內容部分和一個頁腳部分。頁腳部分應該是顯示高度的20%。我認爲這是一個非常常見的用例。Android佈局LinearLayoutProblem
我嘗試了一些方法,但最終沒有成功。
我將如何實現這個?
恩!
我想有一個網站,其中包含一個垂直佈局,有一個內容部分和一個頁腳部分。頁腳部分應該是顯示高度的20%。我認爲這是一個非常常見的用例。Android佈局LinearLayoutProblem
我嘗試了一些方法,但最終沒有成功。
我將如何實現這個?
恩!
<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)以瞭解此操作的簡要說明。
這是什麼爲我工作顯示頁腳與廣告。
<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,對吧?只需設置您的內容和頁腳的佈局既FILL_PARENT的高度,並給內容區域的8 layout_weight和頁腳的2
我不得不爲每個內部LinearLayout添加android:layout_height =「0dip」。但是,它運作良好。恩! – Fesp 2011-01-07 15:20:44