私は次の単純なレイアウトになっています。RelativeLayout TextViewの右から見る
<?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">
<TextView
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:text="@string/long_string"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<CheckBox
android:id="@+id/y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/x"
android:layout_toEndOf="@+id/x"
android:layout_centerVertical="true" />
</RelativeLayout>
このレイアウトは、テキストビューのテキストの長さが短い場合に問題ありません。チェックボックスは、テキストビューの右側に配置されます。しかし、テキストが長くなり、たぶんラップする場合でも、チェックボックスはビューから押し出されます。それはもはや見えません。私はチェックボックスが常に画面の幅全体を埋める場合でも、テキストビューの右側に表示されるようにしたいと思います。
レイアウトをLinearLayoutで書き直そうとしましたが、どちらも動作しません。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:text="@string/long_string"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<CheckBox
android:id="@+id/y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
相対レイアウトでこれを達成するための秘訣はありますか?私はどういうわけか、デフォルトで相対レイアウトからこの動作を期待しています。おかげで、あなたはあなたのビュー(のTextViewとチェックボックス)を作るために、プロパティlayout_weightを置くべき
私はその可能性を認識していますが、このレイアウトが大きなスクリーンのタブレットではうまく動作しないため、チェックボックスを親の右側ではなくテキストビューの右側にしたいと尋ねました。短い文字列では、2つの要素があまりにも離れているためです。 –
あなたはこの相対レイアウトを別のアイテム(ビュー)として取り、それをあなたの親レイアウトに含めることができます。 –
あなたは何を意味するのか分かりません。明確にできますか?このレイアウトを親ビューに含めても、何も振る舞いは変わりません:) –