Android RadioButton 图片位置与大小实例详解
作者:zst1303939801 发布时间:2022-04-12 18:00:20
标签:Android,RadioButton
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


猜你喜欢
- 1、首先创建一个测试实体类Person,并携带如上注解,其注解的作用描述在messagepackage com.clickpaas.pojo
- 本文实例为大家分享了Unity实现弹球打砖块游戏的具体代码,供大家参考,具体内容如下创作界面记录摄像机所需脚本1射线shexianusing
- 1. 公共字段自动填充1.1 问题分析在新增员工时需要设置创建时间、创建人、修改时间、修改人等字段,在编辑员工时需要设置修改时间、修改人等字
- java ,javaw 和 javaws 的区别:首先,所有的这些都是java的启动装置,java.e
- 一、下载安装包 1. JDK1.8百度云下载路径:百度网盘下载链接: https://pan.baidu
- 1.springboot使用log4j2springboot使用的common-logging,底层兼容各种日志框架如,log4j2,slf
- 前言 SQLite是一种轻量级的小型数据库,虽然比较小,但是功能相对比较完善,一些常见的数据库基本功能也具有,在现在的嵌入式系统中使用该数据
- 本文为大家分享了Tablayout简单的使用方法,供大家参考,具体内容如下一、TabLayout普通用法在项目中使用viewpager的时候
- C++虚类相当于java中的抽象类,与接口的不同之处是:1.一个子类只能继承一个抽象类(虚类),但能实现多个接口2.一个抽象类可以有构造方法
- 前言项目流程图如下:这里我们通过:163邮箱来实现激活码发送qq邮箱来进行接收学习之前需要掌握的知识springboot的基本使用方法mys
- 一、Java异常架构与异常关键字Java异常简介Java 异常是 Java 提供的一种识别及响应错误的一致性机制。Java 异常机制可以使程
- 在本文中,我们将介绍二进制搜索相对于简单线性搜索的优势,并介绍它在 Java 中的实现。1. 需要有效的搜索假设我们在wine-sellin
- 工具栏:就是上面有个好多的快捷按钮的那个栏,比如撤销,上传,下载设置,扳手按钮,等等。目录栏:就是刚刚装的时候,这个会显示,但是不知道怎么关
- 今天给大家介绍一下如何实现一款简约时尚的安卓登陆界面。大家先看一下效果图当用户输入时动态出现删除按钮 现在先罗列一下技术点:1.如何使用圆角
- java中实现list或set转map的方法在开发中我们有时需要将list或set转换为map(比如对象属性中的唯一键作为map的key,对
- 在JavaBeans中有这样的一个描述:当一些信息需要使用类似于字典嵌套字典再嵌套列表这种很深的结构来储存的时候,请改用类来储存。实际上,这
- 一、引言以前在饿了么上面订餐的时候,曾经看到过这么一个特效,就是将商品加入订单时,会有一个小球呈抛物线状落入购物车中,然后购物车中的数量会改
- 在application.xml加上以下配置mybatis-plus.configuration.map-underscore-to-cam
- 前言:在 Spring 中, IOC 是很重要的概念,其本质就是 map 结构,存储容器和业务 Be
- 网上有很多人探讨Java中异常捕获机制try...catch...finally块中的finally语句是不是一定会被执行?很多人都说不是,