ボタン B1 と B2 を行の右側に配置し、ボタン A1 と A2 をその行の残りのスペースの中央に配置したいと考えています。
ボタン Aを 2 回ラップせずにこれは可能ですか?
質問を具体的にするための詳細は次のとおりです。
Eclipse は@id/buttonAx
、「この LinearLayout レイアウトまたは RelativeLayout の親はおそらく役に立たない」と言って、2 つの親レイアウトを批判します。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/myRightMostLL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/buttonB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B1" />
<Button
android:id="@+id/buttonB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B2" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/myRightMostLL">
<LinearLayout
android:id="@+id/remainderLL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/buttonA1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A1" />
<Button
android:id="@+id/buttonA2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A2" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
それでも、ボタン B を配置した後に残ったスペースにボタン A を中央に配置するには、この無駄が必要でした。ボタン A の親ラッパー レイアウトを 1 つだけ使用して同じ効果を得ることができますか?
このようなレイアウトでは、@id/myRightMostLL がファイルの最初に表示されることが本当に必要かどうかも疑問に思うことがよくあります。