你好,游客 登录 注册 搜索
背景:
阅读新闻

Android 自定义RadioButton(单选按钮)图标随便定

[日期:2012-08-26] 来源:Linux社区  作者:jj120522 [字体:大 中 小]
也许你会发现了,因为我们为了提高效率,重用了listview个convertView.所以会出现这种bug,解决方法也很简单,只需要我们把上面代码更换为
  1. final RadioButton radioButton;  
  2.                 radioButton = new RadioButton(context);  
  3.               

虽说这样效率有点低,但是有时候我们需要则断一下,只要能实现效果,偶尔对性能放下水也是OK的,何况这种情况下不可能有那么多列.

项目实现样式:

    

看起来还凑合吧。

这里我把代码上传一下,不足的地方,自己可以进行调整,我只是提供个思路.

利用RMAN对数据库进行备份与恢复 PPT文档下载地址

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2012年资料/8月/26日/Android 自定义RadioButton(单选按钮)图标随便定

 

第二种方法:对RadioButton给定样式进行改造

看配置文件

seletor.xml  and style.xml 

  1. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  2.   
  3.     <item android:drawable="@drawable/radio_checked" android:state_checked="true" android:state_enabled="true"></item>  
  4.     <item android:drawable="@drawable/radio_unchecked" android:state_checked="false" android:state_enabled="true"></item>  
  5.   
  6. </selector>  
  1. <resources xmlns:android="http://schemas.android.com/apk/res/android">  
  2.   
  3.     <style name="RadioButtonStyles">  
  4.         <item name="android:button">@drawable/selector</item>  
  5.     </style>  
  6.   
  7. </resources>  
最后只需要在RadioButton中引用即可.
  1. <RadioGroup  
  2.     android:id="@+id/rg_main"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="wrap_content" >  
  5.   
  6.     <RadioButton  
  7.         android:id="@+id/button1"  
  8.         style="@style/RadioButtonStyles"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="5K" />  
  12.   
  13.     <RadioButton  
  14.         android:id="@+id/button2"  
  15.         style="@style/RadioButtonStyles"  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="wrap_content"  
  18.         android:text="10K" />  
  19. </RadioGroup>  

这种方式很简单吧,不过我觉的应用范围没有上面自定义来的广,比如说上面我做的项目中,RadioButton中的text有两项,这样我们用RadioButton就无法实现了,遇到比较复杂的RadioButton选择自定义是比较好的.

针对RadioButton 就说这么多了,希望对你有帮助.

linux
相关资讯       Android开发入门 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* katechris会员 发表于 2015/7/10 9:57:56
很详细很有用,楼主好人!!!