更改文本出现在单选按钮上的一侧 [英] Change the side the text appears on a radio button

查看:19
本文介绍了更改文本出现在单选按钮上的一侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法切换文本出现在 android 单选按钮上的一侧?

I was wondering if there was a way to switch the side that text appears on a radio button in android?

推荐答案

我想做同样的事情,而不必扩展另一个类(或两个类,因为您至少必须扩展 CompoundButton RadioButton) 用于从一开始就应该成为实现的一部分的东西.因为我使用的是 RadioGroup,如果你在布局容器中放置一个 RadioButton 和一个 TextView,它将无法工作.诚然,我的解决方案不仅仅是有点骇人听闻,但是 - 它有效.

I wanted to do the same thing, without having to extend yet another class (or two, as you would have to at least extend CompoundButton and RadioButton) for something that should be part of the implementation from the beginning. Since I was using a RadioGroup, which will not work if you put say, a RadioButton and a TextView in a layout container. My solution is admittedly more than a bit hackish, but - it works.

1) 将 Padding left 设置为 402) 将左布局边距设置为 -36dp

1) Set Padding left to 40 2) Set Layout margin left to -36dp

此时,原始单选按钮将在视图之外,而您的文本视图将位于最左侧,边距为 4dp.

At this point, the original radio button will be outside the view, and your text view will be sitting on the far left with a 4dp margin.

3) 将 Drawable 权限设置为 @android:drawable/btn_radio

3) Set Drawable right to @android:drawable/btn_radio

您现在将拥有一个本机 RadioButton,左侧有文本,右侧有一个按钮,可与 RadioGroup 配合使用.

You'll now have a native RadioButton with the text on the left and a button on the right, that will work with a RadioGroup.

@CommonsWare

@CommonsWare

值得一提的是,针对这个特定问题提出人机界面指南非常具有讽刺意味.特别是考虑到调整 RadioButton 布局以将按钮放在最右侧,将与 Spinner 菜单的布局保持一致.我完全同意你对此事的看法——但很可能 NickTFried 试图弥补 Android 在这方面的挂起".

It's worth mentioning that it's incredibly ironic to bring up Human Interface Guidelines in response to this particular question. Especially considering that adjusting the RadioButton layout to place the button on the far right, would achieve consistency with the layout of the Spinner menu. I completely agree with your opinion on the matter - but it's quite possible that NickTFried was trying to compensate for Android "hanging" itself in that regard.

这篇关于更改文本出现在单选按钮上的一侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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