一个单选按钮,标签在Android中的添加保证金? [英] Add margin between a RadioButton and its label in Android?

查看:164
本文介绍了一个单选按钮,标签在Android中的添加保证金?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能增加一个单选按钮,并同时仍使用Android的内置组件标签之间的空间一点点?默认情况下,文本看起来有点揉成一团。

Is it possible to add a little bit of space between a RadioButton and the label while still using Android's built-in components? By default the text looks a little scrunched.

<RadioButton android:id="@+id/rb1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="My Text"/>

我试了几件事情:

I've tried a couple of things:

  1. 指定margin和padding似乎添加空间整个元件周围(按钮和文本,在一起)。这是有道理的,但并没有做什么,我需要的。

  1. Specifying margin and padding seem to add space around the entire element (button and text, together). That makes sense, but doesn't do what I need.

创建通过XML指定图像的选中和未选中状态,然后再加入一些额外的像素向右侧的每个图像的一个自定义的可拉伸。这应该工作,但现在你正在加紧默认的UI之外。 (世界没有结束,但不理想)

Creating a custom drawable via XML specifying images for the checked and unchecked states, then adding a few extra pixels to the right side of each image. This should work, but now you are stepping outside the default UI. (Not the end of the world, but not ideal)

添加额外的空格,以每个标签的开头。看来Android修剪前导空格字符,如我的字符串,但指定UNI code U + 00A0,如\ u00A0My字符串的伎俩。这工作,但似乎有点脏。

Add extra whitespace to the beginning of each label. Android seems to trim a leading space character, as in " My String", but specifying unicode U+00A0, as in "\u00A0My String" does the trick. This works, but it seems kinda dirty.

没有更好的办法?

推荐答案

有关的人现在在读这一点。接受的答案将导致对新API的一些布局问题造成太大的填充。

For anyone reading this now. The accepted answer will lead to some layout problems on newer apis causing too much padding.

在API&LT; = 16你可以设置填充留在单选按钮来设置相对于单选按钮的看法边界的填充。另外一个补丁9背景也改变了看法范围相对于视图。

On API <= 16 you can set padding left on the radio button to set the padding relative to the radio button's view bounds. Additionally a patch nine background also changes the view bounds relative to the view.

在API 17中的左填充是相对于所述单选按钮可绘。同样适用于约一个补丁九岁。为了更好地说明填充的差异见附件截屏。

On API 17 the left padding is in relation to the radio button drawable. Same applies to the about a patch nine. To better illustrate padding differences see the attached screen shot.

如果您通过$ C $挖c您会发现在17 API的新方法被称为<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.2.2_r1/android/widget/CompoundButton.java#CompoundButton.getHorizontalOffsetForDrawables%28%29">getHorizontalOffsetForDrawables.计算左填充用于无线电按钮(因此在图像中示出的额外的空间)时,这种方法被称为

If you dig through the code you will find a new method in api 17 called getHorizontalOffsetForDrawables. This method is called when calculating the left padding for a radio button(hence the additional space illustrated in the picture).

TL; DR你应该有单选按钮样式最小SDK要支持和另一种风格的API 17 +

TL;DR You should have radio button style for the min sdk you are supporting and another style for api 17+

这篇关于一个单选按钮,标签在Android中的添加保证金?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆