相关疑难解决方法(0)

在Android中添加RadioButton及其标签之间的边距?

是否可以在仍然使用Android的内置组件的同时在RadioButton和标签之间添加一点空间?默认情况下,文本看起来有点紧张.

<RadioButton android:id="@+id/rb1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="My Text"/>
Run Code Online (Sandbox Code Playgroud)

我尝试了几件事:

  1. 指定边距和填充似乎在整个元素周围添加空间(按钮和文本,一起).这是有道理的,但不能做我需要的.

  2. 通过XML创建自定义drawable,为已检查和未检查的状态指定图像,然后在每个图像的右侧添加一些额外的像素.这应该可行,但现在您已经超出默认UI.(不是世界末日,但不是理想的)

  3. 在每个标签的开头添加额外的空格.Android似乎修剪了一个领先的空格字符,如"我的字符串",但是指定unicode U + 00A0,就像"\ u00A0My String"一样.这有效,但似乎有点脏.

更好的解决方案?

android radio-button

77
推荐指数
6
解决办法
6万
查看次数

RadioGroup 允许选择多个 RadioButtons

我有一个用 XML 定义的 RadioGroup,它有两个 RadioButton。但是,我需要将标签显示在按钮本身的左侧,标签向左对齐,按钮向右对齐。为此,我使用了一个包含 TextView 和 RadioButton 的相对布局,没有text. 这大概是布局的样子:

<RadioGroup android:id="@+id/foo" android:layout_height="wrap_content" android:layout_width="match_parent">
    <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent">
        <TextView android:text="@string/bar_one" android:layout_alignParentLeft="true" android:layout_height="wrap_content" android:layout_width="wrap_content" />
        <RadioButton android:id="@+id/bar1" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </RelativeLayout>
    ...
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)

这显示了我期望的方式,但我发现 RadioGroup 允许选择多个 RadioButton。当我去掉RelativeLayouts和TextViews时,RadioButtons直接嵌套在RadioGroup下,只能选择一个。有没有办法包装我的单选按钮但同时选择多个?

如果没有,有没有更好的方法来完成我所追求的造型?

android

5
推荐指数
1
解决办法
4280
查看次数

标签 统计

android ×2

radio-button ×1