私の Android アプリには、それぞれが異なるアクティビティを起動する 3 つのボタンを表示するかなり単純なアクティビティがあります。現在、RelativeLayout を使用して中央のボタンを水平方向と垂直方向の両方の中央に配置し、上部と下部のボタンを中央のボタンから 30 dp 離して配置します (水平方向にも中央に配置します)。
ただし、私がやりたいのは、ボタンを画面幅の特定の割合になるように伸ばすことです。これを行う方法とボタンを中央に保つ方法がわかりません。ボタンの両側の LinearLayout で「フィラー」として使用できる適切なオブジェクトはありますか (ウェイトを設定するだけで済みます)。または、LinearLayout を使用せずにこれを行う方法はありますか?
現状のレイアウトの XML は次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:onClick="button1Callback"
android:text="@string/button1Label" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="button2Callback"
android:text="@string/button2Label" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="@string/button3Label" />
</RelativeLayout>