Android RadioButton 图片位置与大小实例详解
作者:zst1303939801 时间:2022-04-12 18:00:20
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>
效果:
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/u012246458/article/details/50387308
标签:Android,RadioButton
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
探究Java常量本质及三种常量池(小结)
2023-06-17 10:28:17
![](https://img.aspxhome.com/file/2023/8/83058_0s.png)
剖析设计模式编程中C#对于组合模式的运用
2023-04-09 07:48:17
![](https://img.aspxhome.com/file/2023/4/100164_0s.png)
SpringBoot 上传文件判空以及格式检验流程
2023-01-19 05:07:36
![](https://img.aspxhome.com/file/2023/5/61405_0s.png)
HighCharts图表控件在ASP.NET WebForm中的使用总结(全)
2022-07-13 02:11:12
![](https://img.aspxhome.com/file/2023/9/108849_0s.png)
C# 微信支付回调验签处理的实现
2021-07-27 01:57:34
java实现文件夹解压和压缩
2022-06-07 03:00:39
Mybatis常用分页插件实现快速分页处理技巧
2022-12-25 00:03:45
java 键盘输入一个数,输出数组中指定元素的示例
2023-11-24 20:31:14
Java的外部类为什么不能使用private和protected进行修饰的讲解
2023-06-29 00:45:57
java进阶之了解SpringBoot的配置原理
2022-05-08 05:10:36
![](https://img.aspxhome.com/file/2023/0/64000_0s.png)
android编程实现设置、打开wifi热点共享供他人连接的方法
2021-12-05 03:39:41
Java源码解析HashMap的keySet()方法
2023-11-11 06:33:05
![](https://img.aspxhome.com/file/2023/7/58837_0s.png)
SpringBoot去除参数前后空格和XSS过滤
2023-07-27 02:33:56
![](https://img.aspxhome.com/file/2023/6/102656_0s.png)
java8中:: 用法示例(JDK8双冒号用法)
2023-11-25 06:21:21
使用spring框架实现数据库事务处理方式
2022-03-01 14:38:13
![](https://img.aspxhome.com/file/2023/8/62738_0s.png)
Java毕业设计实战之线上水果超市商城的实现
2021-09-15 19:23:01
![](https://img.aspxhome.com/file/2023/9/62779_0s.png)
C#检查指定对象是否存在于ArrayList集合中的方法
2023-07-28 00:45:17
JavaWeb 使用DBUtils实现增删改查方式
2023-01-31 04:31:48
![](https://img.aspxhome.com/file/2023/4/96814_0s.png)
C#事件中关于sender的用法解读
2022-09-30 20:28:39
![](https://img.aspxhome.com/file/2023/5/84445_0s.png)
C#实现支付宝沙箱支付的项目实践
2021-07-29 17:18:18
![](https://img.aspxhome.com/file/2023/9/82109_0s.jpg)