【发布时间】:2021-11-24 16:05:28
【问题描述】:
我有一个令人难以置信的问题。我有 1 个带有 2 个单选按钮的单选按钮,我希望每个单选按钮的宽度都是 match_parent,文本在左侧对齐。但是我不知道为什么,第一个是右对齐的,你可以在图片上看到
这是代码
<RadioGroup
android:id="@+id/rgPasswordSendMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="32dp"
android:divider="?android:attr/dividerHorizontal"
android:orientation="vertical"
android:showDividers="middle|end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<RadioButton
android:id="@+id/phoneRadioButton"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:text="******6043" />
<RadioButton
android:id="@+id/emailRadioButton"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:text="test@test.com" />
</RadioGroup>
当我仅将 ******6043 更改为 ****** 或其他文本时,标签在左侧很好地对齐。 基于enter link description here,我添加了
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorSingle"
android:background="?android:selectableItemBackground"
但没有任何改变。
为什么会这样以及如何解决?
【问题讨论】:
-
你能用
match_content作为宽度,wrap_content作为高度 -
不会改变任何东西
标签: android radio-button alignment text-alignment