RadioButton 将文本左对齐,按钮右对齐
RadioButton align text to left side and button to right
我希望我的单选按钮的宽度与屏幕匹配,并使其文本与屏幕左侧对齐,按钮与右侧对齐。目前我的布局如下所示:
<?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="vertical">
<RadioGroup
android:id="@+id/optionsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/sortingOptionRadioButton"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:layoutDirection="rtl"
android:text="Popularity"
android:layout_margin="@dimen/e2_space_small"
/>
</RadioGroup>
</LinearLayout>
在预览中它看起来和我想要的一样,但是当我在我的设备上启动应用程序时,文本和按钮都与右侧对齐。
我怎样才能让文本和按钮与相对的边对齐?
尝试在单选按钮组和单选按钮中添加布局重力和重力属性
android:layout_gravity="start"
android:gravity="left"
我希望我的单选按钮的宽度与屏幕匹配,并使其文本与屏幕左侧对齐,按钮与右侧对齐。目前我的布局如下所示:
<?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="vertical">
<RadioGroup
android:id="@+id/optionsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/sortingOptionRadioButton"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:layoutDirection="rtl"
android:text="Popularity"
android:layout_margin="@dimen/e2_space_small"
/>
</RadioGroup>
</LinearLayout>
在预览中它看起来和我想要的一样,但是当我在我的设备上启动应用程序时,文本和按钮都与右侧对齐。 我怎样才能让文本和按钮与相对的边对齐?
尝试在单选按钮组和单选按钮中添加布局重力和重力属性
android:layout_gravity="start"
android:gravity="left"