android - 如何调整android中单选按钮之间的间距

标签 android android-layout android-radiobutton

在我的 android 应用程序中使用单选按钮选择屏幕 View 。我希望单选按钮水平对齐。我尝试了如下所示的布局 xml。

<?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" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Views"
    android:paddingLeft="10dp"
    android:textSize="20sp"
    />

<RadioGroup
    android:id="@+id/radioView"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:measureWithLargestChild="true"
    android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radioViewSingle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/single"
            android:layout_weight="1"
            android:checked="true" />

        <RadioButton
            android:id="@+id/radioView2by2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/view2x2" />

        <RadioButton
            android:id="@+id/radioView3by3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/view3x3" />

        <RadioButton
            android:id="@+id/radioView4by4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/view4x4" />
</RadioGroup>
</LinearLayout>

enter image description here 使用上面的xml代码获得的输出

但我期待低于输出

enter image description here

提前致谢

最佳答案

不使用 android:drawableRight,而是使用 android:drawableLeft。

我刚刚测试了这个,它按预期工作

关于android - 如何调整android中单选按钮之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313174/

相关文章:

Android:向按钮的所有侧面添加阴影?

android - 如何在小部件右侧创建没有向下三角形的android微调器

Android RadioButton *带有*图标并居中对齐

android - ConstraintLayout、RadioGroup和两列RadioButton

android - 如何向 list 中的接收者发送自定义广播操作?

java - 是否可以在 Android 中运行 H2O 模型?

android - 膨胀类 frameLayout 时出错

java - 如何检查 firebase 数据库中是否存在一个值 - android

java - 如何检测某个 Sprite 是否在特定时间间隔内未被触摸