Android中如何设置RadioButton在文字的右边,图标在左边

from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referral

Android中如何设置RadioButton在文字的右边,图标在左边???

解决方法  :
第一步:
android:button="@null"这条语句将原来系统的RadioButton图标给隐藏起来。
第二步:
 android:drawableRight="@android:drawable/btn_radio"这条语句
在原来图标的右边添加一个系统自带的btn_radio图标,我想RadioButton就是在btn_radio图标上进行封装而已。

<?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/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

<RadioButton
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           android:button="@null"
            android:checked="true"
            android:drawableRight="@android:drawable/btn_radio"
            android:paddingLeft="10dp"
            android:text="RadioButton" />

<RadioButton
            android:id="@+id/button2"
            android:layout_width="319dp"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:paddingLeft="10dp"
            android:text="RadioButton" />

</RadioGroup>
</LinearLayout>

demo下载
http://download.csdn.net/detail/sunnyfans/4521592

附参考网站:
http://www.haogongju.net/art/1422253

小结:

今天在实现RadioGroup单选时,要求文字在左边,选择图标在右边,而android系统自带的RadioGroup是图标在左边,文字在右边,既然我有这个需求,遇到这个问题,那么肯定有其他人也有这个需求,于是也就应该有实现它的方法。因为问题已经发生了,这个世界也就是在不断解决未知问题的过程中不断发展进步,即:需求,问题是发明、发展的原始推动力。知识是为解决问题,或者描述某现象的而诞生。所以以后不管遇到什么问题,不要畏惧,既然问题已经发生了,即一定会有解决它的办法,这时就需要自己去思考,思考这个问题发生的环境,分析问题,然后定位问题原因(二分法)<先猜测,再求证>,定位后再思考如何去解决。不断提醒自己养成这种遇到问题,分析问题,进而尝试去解决问题的习惯。

知识收获:
认识到android系统图标的重要性,可以这样使用:
 android:button="@null"将图标给隐藏,然后再用android:drawableRight="@android:drawable/btn_radio"在右边再生成一个图标,再用android:text="文字内容"在隐藏图标的位置显示文字。
反复思考:
 android:button="@null"
android:drawableRight="@android:drawable/btn_radio
这提供了一种通用方法。

附:demo下载
http://download.csdn.net/detail/sunnyfans/4521592

时间: 2024-08-24 22:53:28

Android中如何设置RadioButton在文字的右边,图标在左边的相关文章

Android设置RadioButton在文字的右边

效果图如下: [html] view plaincopy <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fi

【转载】深度解析Android中字体设置

原文:http://mobile.51cto.com/android-265238.htm 1.在Android XML文件中设置字体 可以采用Android:typeface,例如android:typeface=”monospace”.在这里例子中我们在Activity中对android:text=”Hello, World! 您好”分别进行了四种显示方式,依次为“Sans”,“serif”,“monospace”和系统缺省方式(经试验缺省采用采用sans).英文字体有差异,貌似中文字体没有

深度分析:Android中Mms设置页面更改短信中心号码流程

相关控件初始化方法:showSmscPref private void showSmscPref() { int count = MSimTelephonyManager.getDefault().getPhoneCount(); boolean airplaneModeOn = Settings.System.getInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; for (int i = 0; i < c

android中RadioGroup、RadioButton、Spinner、EditText用法详解(含示例截图和源代码)

为了保护版权.尊重原创,转载请注明出处:http://blog.csdn.net/u013149325/article/details/43237757,谢谢! 今天在项目中用到了android中常用的RadioGroup.RadioButton.Spinner.EditText等控件,在此介绍一下它们的用法,希望对需要的朋友有帮助. 一.RadioGroup和RadioButton的使用 RadioButton就是我们常见的单选按钮,一个RadioGroup可以包含多个单选按钮,但是每次只能选

android中xml设置Animation动画效果详解

在 android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation 画面转换动画. tweened animation 渐变动画有以下两种类型: 1.alpha 渐变透明度动画效果 2.scale 渐变尺寸伸缩动画效果 frame by frame animation 画面转换动画有以下两种类型: 1.translate 画面转换位置移动动画效果 2.rotate

android 中 listview 设置自动匹配高度

1.布局文件 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" andr

Android中单选框RadioButton的基本用法

总结一下设置图标的三种方式: (1)button属性:主要用于图标大小要求不高,间隔要求也不高的场合. (2)background属性:主要用于能够以较大空间显示图标的场合. (3)drawableLeft属性:主要用于对图标与文字之间的间隔有要求的场合. 注意使用 background 或者 drawableLeft时 要设置 android:button="@null" 监听: radioGroup.setOnCheckedChangeListener(new RadioGroup

Android中如何设置字体大小

在本文中,我们将介绍一些简单的处理方式,帮助开发人员轻松编写出能够应对各类设备型号的应用程序文本方案,同时为用户提供自定义文字尺寸功能.别担心,整个过程没什么难度,只要一步步按指南进行操作,大家再也不用为调整显示效果而劳心伤神了. 在这篇上手教程中,我们将讨论一些实用性步骤,指引开发人员在拥有足够灵活性的前提下保证文字清晰易读,同时使自己的产品能够适应多种屏幕类型及各类用户显示设定. 用户如何按需求配置字体设定 首先要强调一点,某些用户可能存在视力障碍甚至几近失明,他们无法顺利阅读一般尺寸下的文

Android中TextView设置字体

最近项目中出现把字体设置成宋体,微软雅黑,黑体,楷体等的需求; 度娘发现Android系统默认支持三种字体,分别为:"sans", "serif", "monospace",除此之外还可以使用其他字体文件(*.ttf) 代码如下: //得到TextView控件对象        TextView textView =(TextView)findViewById(R.id.custom); //将字体文件保存在assets/fonts/目录下,创建