android 修改RadioButton的drawTop图片大小
来源:互联网 发布:excel2013快速选择数据 编辑:程序博客网 时间:2024/05/16 15:59
最近做项目用的是RadioGroup+Fragment进行来回切换,这样方便也很多,但是也出现问题,drabTop的图片不能改变大小,所以写此博客记录一下
效果图
/** * Created by Sinocall on 2015-10-21. */public class MyRadioButton extends RadioButton{ //图片大小 //private int drawableSize; public MyRadioButton(Context context) { this(context,null); } public MyRadioButton(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyRadioButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton); //drawableSize = a.getDimensionPixelSize(R.styleable.MyRadioButton_rbDrawableTopSize, 50); Drawable drawableTop = a.getDrawable(R.styleable.MyRadioButton_rbDrawableTop); //释放资源 a.recycle(); setCompoundDrawablesWithIntrinsicBounds(null,drawableTop,null,null); } @Override public void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) { super.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); if(top != null){
//这里只要改后面两个参数就好了,一个宽一个是高,如果想知道为什么可以查找源码 top.setBounds(0,0,70,60); } setCompoundDrawables(left,top,right,bottom); }}
在values下新建一个attrs.xml然后把下面代码复制进去就好
<declare-styleable name="MyRadioButton"> <attr name="rbDrawableTopSize" format="dimension"/> <attr name="rbDrawableTop" format="reference"/></declare-styleable>在布局文件中直接使用,注意声明命名空间。就这么简单任性即可解决,本人也是在网上搜集之后改的!
0 0
- android 修改RadioButton的drawTop图片大小
- Radiobutton 设置drawtop图片大小
- RadioButton的图片大小设置
- radioButton图片大小的设置
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- 设置Android中RadioButton的图片大小和位置
- Android自定义RadioButton以控制drawableTop等方向的图片大小
- RadioButton图片居中and修改图片大小
- Android 调整 TextView,CheckBox,RadioButton中图片大小
- 安卓 RadioButton的图片大小设置 draw的图片大小设置
- RadioButton动态改变drawableTop的图片大小
- toolStrip 按钮图片大小的修改
- 修改一个图层内的图片大小
- 修改图片大小
- 修改图片大小
- 修改图片大小
- ubunut sublime text3 中文输入法问题
- UML---面向对象技术
- 算法 + 算法 = 新算法
- leetcode 14 Longest Common prefix
- 使用python实现身份证号码的规则校验
- android 修改RadioButton的drawTop图片大小
- a href=#与 a href=javascript:void(0) 的区别
- 1005. 继续(3n+1)猜想 (25)
- TypeScript学习-TypeScript数据类型简介
- hdu5494
- Mahout-kmeans命令行文本文件聚类
- nginx空主机头
- 信管 数据库 网管 总结
- 机器学习(十二)学习SVM支持向量机过程中的引申