我希望我的单选按钮的宽度与屏幕相匹配,并使其文本与屏幕左侧对齐,按钮在右侧。目前我的布局如下:
<?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"