画面の下部に 5 つのボタンがあります (重みがそれぞれ 1 の線形レイアウトにグループ化されています。スクリーンショットでは、b1-b5 の上の行)。ただし、テキストが複数の行にある場合、その特定のボタンは、その親の外側であっても押し下げられます。各ボタンの高さは設定値であり、すべてのボタンで同じです。next >
ボタンは正しい位置にある唯一のボタンです。いくつかのXMLの下にありますが、それは私にはすべて正常に思えます:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/h"
android:orientation="horizontal" >
<Button }
android:layout_width="0dp" }
android:layout_height="@dimen/h" } x5
android:layout_weight="1"/> }
</LinearLayout>
ボタン b1 ~ b5 の LinearLayout の margin_top は 10 dp です。
スクリーンショット:
赤い線は、ボタンが整列する場所です。青い線は 2 行のテキスト、緑は 3 行のボタンです。
スクリーンショットによると、ボタンに含まれるテキスト行が多いほど、ボタンが少し押し下げられています。テキストが多すぎる場合、ボタンが押されないようにするにはどうすればよいですか? 均等に重み付けする必要があるため、relativelayout を使用してそれらを alignTop にすることはできません
編集: 完全な (ただし短縮された) XML
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="6dp">
<LinearLayout
android:id="@+id/panel1"
android:layout_width="match_parent"
android:layout_height="@dimen/h"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/margin"
android:layout_centerHorizontal="true">
<Button
android:layout_width="0dp" }
android:layout_height="@dimen/h" }x5
android:layout_weight="1"/> }
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/text"
android:layout_alignParentTop="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:background="@color/black"
android:textColor="@color/white"
android:text="@string/longtext">
</TextView>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/panel1"
android:gravity="bottom">
<LinearLayout
android:id="@+id/panel2"
android:layout_width="match_parent"
android:layout_height="@dimen/h"
android:orientation="horizontal">
<Button
android:layout_width="0dp" }
android:layout_height="@dimen/h" }x5
android:layout_weight="1"/> }
</LinearLayout>
</RelativeLayout>
</RelativeLayout>