LinearLayout
はandroid:layout_weight
でこれを処理できます。例えば、ここではそれぞれ50%、30%、及び高さの20%を占めて三個のButton
ウィジェットを含むレイアウトである:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="50"
android:text="@string/fifty_percent"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="30"
android:text="@string/thirty_percent"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="20"
android:text="@string/twenty_percent"/>
</LinearLayout>
ただし、単に任意の時点でその任意のウィジェットを宣言することができませんあなたのレイアウトファイルでは、画面サイズの任意の割合を占める必要があります。あなたはJavaで計算を実行し、必要に応じてウィジェットのLayoutParams
を調整することもできます。
は、あなたがあなたの画面の2つの部分をしたいと言うことを意味しますか?または、表示されているときに親全体の下位27%をカバーする別のビューの内側にあるビューを希望しますか? – brianestey