【问题标题】:RadioButton align text to left side and button to rightRadioButton 将文本对齐到左侧,将按钮对齐到右侧
【发布时间】:2019-02-26 22:31:26
【问题描述】:

我希望我的单选按钮具有与屏幕匹配的宽度,并且其文本与屏幕左侧对齐,按钮与右侧对齐。目前我的布局如下所示:

<?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:layoutDirection="rtl" 导致了这种行为,请尝试删除此行。

标签: android android-layout android-radiobutton


【解决方案1】:

尝试在单选按钮组和单选按钮中添加布局重力和重力属性

 android:layout_gravity="start"
 android:gravity="left"

【讨论】:

  • 我还添加了android:textAlignment="textStart",它起作用了
猜你喜欢
  • 1970-01-01
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-11
  • 2015-03-17
  • 1970-01-01
相关资源
最近更新 更多