アプリの XML レイアウトを作成していて、ボタンをテキストの下に配置する必要がありましたが、LinearLayout を使用して一部のテキストをプロパティの重みで水平方向に配置したため、ボタンは別のレイアウトのままで、プロパティを定義するようになりました。 android:layout_below" で、テキストの ID が見つかりません。では、Java を使用せずにこの問題を解決できる提案はありますか?
これが私のコードです:
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/text3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/text1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text1"
android:gravity="center"
android:text="Button" />
</RelativeLayout>
編集: ボタンは に揃える必要がありますtext1
。アイデアは、align_left、align_right、および align_below の 3 つのプロパティを使用して、ボタンのテキストの幅が同じになるようにすることです。そして、テキストでプロパティを設定するための他のビューがあります。