Android RadioButton 图片位置与大小实例详解

所属分类: 软件编程 / Android 阅读数: 49
收藏 0 赞 0 分享

Android RadioButton 图片位置与大小

Java:

rgGroup = (RadioGroup) findViewById(R.id.re_group); 
    rbWeiHui = (RadioButton) findViewById(R.id.rb_wei_hui); 
    rbAdd = (RadioButton) findViewById(R.id.rb_add); 
    rbMine = (RadioButton) findViewById(R.id.rb_mine); 
 
    //定义底部标签图片大小 
    Drawable drawableWeiHui = getResources().getDrawable(R.drawable.btn_tab_wei_hui_selector); 
    drawableWeiHui.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度 
    rbWeiHui.setCompoundDrawables(null, drawableWeiHui, null, null);//只放上面 
 
    Drawable drawableAdd = getResources().getDrawable(R.drawable.btn_tab_add_selector); 
    drawableAdd.setBounds(0, 0, 168, 120); 
    rbAdd.setCompoundDrawables(drawableAdd, null, null, null); 
 
    Drawable drawableRight = getResources().getDrawable(R.drawable.btn_tab_mine_selector); 
    drawableRight.setBounds(0, 0, 69, 69); 
    rbMine.setCompoundDrawables(null, drawableRight, null, null); 
 
    //初始化底部标签 
    rgGroup.check(R.id.rb_wei_hui);// 默认勾选首页,初始化时候让首页默认勾选 

xml:

<RadioGroup 
    android:id="@+id/re_group" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/app_bg_color" 
    android:orientation="horizontal" > 
 
    <RadioButton 
      android:id="@+id/rb_wei_hui" 
      style="@style/BottomTabStyle" 
      android:layout_marginTop="5dp" 
      android:drawableTop="@drawable/btn_tab_wei_hui_selector" 
      android:textSize="12sp" 
      android:text="xx" /> 
 
    <RadioButton 
      android:id="@+id/rb_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/app_bg_color" 
      android:button="@null" 
      android:drawableTop="@mipmap/ic_add_selected" 
      android:gravity="center" 
      android:paddingTop="10dip" /> 
 
    <RadioButton 
      android:id="@+id/rb_mine" 
      style="@style/BottomTabStyle" 
      android:layout_marginTop="5dp" 
      android:drawableTop="@drawable/btn_tab_mine_selector" 
      android:textSize="12sp" 
      android:text="xx" /> 
  </RadioGroup> 

selected:只写一个selected,其它模仿此

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
 
  <item android:drawable="@mipmap/ic_mine_selected" android:state_checked="true" /> 
  <item android:drawable="@mipmap/ic_mine_normal" /> 
 
 
</selector> 

style:共同的style-中间的是定制的,左右一个风格

<!-- 低栏RadioButton首页下面的标签的样式 --> 
  <style name="BottomTabStyle"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_gravity">center_vertical</item> 
    <item name="android:button">@null</item> 
    <item name="android:padding">5dp</item> 
    <item name="android:drawablePadding">3dp</item> 
    <item name="android:textColor">@drawable/btn_tab_text_selector</item> 
    <item name="android:layout_weight">1</item> 
    <item name="android:gravity">center</item> 
    <item name="android:layout_marginTop">5dp</item> 
  </style> 

效果:

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多精彩内容其他人还在看

Android网络编程之获取网络上的Json数据实例

这篇文章主要介绍了Android网络编程之获取网络上的Json数据实例,本文用完整的代码实例讲解了在Android中读取网络中Json数据的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中的windowSoftInputMode属性详解

这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下
收藏 0 赞 0 分享

Android网络编程之UDP通信模型实例

这篇文章主要介绍了Android网络编程之UDP通信模型实例,本文给出了服务端代码和客户端代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中使用ListView实现漂亮的表格效果

这篇文章主要介绍了Android中使用ListView实现漂亮的表格效果,本文用详细的代码实例创建了一个股票行情表格,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中刷新界面的二种方法

这篇文章主要介绍了Android中刷新界面的二种方法,本文使用Handler、postInvalidate两种方法实现界面刷新,需要的朋友可以参考下
收藏 0 赞 0 分享

Android SDK三种更新失败及其解决方法

这篇文章主要介绍了Android SDK三种更新失败及其解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(一)

Android3.0(API level 11)开始,Android设备不再需要专门的菜单键。随着这种变化,Android app应该取消对传统6项菜单的依赖。取而代之的是提供anction bar来提供基本的用户功能
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(二)

这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu)
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(三)

今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习,需要的朋友可以参考下
收藏 0 赞 0 分享

Android显示网络图片实例

这篇文章主要介绍了Android显示网络图片的方法,以实例形式展示了Android程序显示网络图片的方法,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多