カスタムの背景、テキスト、およびテキストの右側に画像を備えた2つの同じサイズのラジオボタンを作成したかったのです。これらは標準の「ボタン」とは非常に異なるため、クリック可能な「RelativeLayout」を使用して作成しました。
テキストと画像の高さは異なりますが、それぞれをボタンの垂直方向の中央に配置したいと思います。また、テキストと画像の組み合わせをボタンの水平方向の中央に配置したいと思います。この2番目の部分は、私が問題を抱えている部分です。中心から外れていて、左側に近いです。下の画像では、左側が私が欲しいものですが、右側が起こっていることです。ボタンの1つ(テキストが長いもの)の画像も小さくなります...ボタンの右側にはまだ十分なスペースがありますが。
これが私のコードです:
<LinearLayout
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/my_button"
android:background="@drawable/radio_button"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="@+id/button_textview"
android:text="@string/button_label"
android:textAppearance="?android:attr/textAppearanceButton"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<ImageView
android:contentDescription="@string/image_description"
android:id="@+id/button_imageview"
android:layout_centerVertical="true"
android:src="@drawable/my_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button_textview">
</ImageView>
</RelativeLayout>
<RelativeLayout
... same thing for the second button ...
</RelativeLayout>
</LinearLayout>
私は何が間違っているのですか?