1,values/attrs.xml 文件中:自定义rb_width 和 rb_height 两个属性:

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="MyRadioButton"><attr name="rb_width" format="dimension"/><attr name="rb_height" format="dimension"/></declare-styleable>
</resources>

2,自定义RadioButton,此方法对TextView内的图标也适用(自定义TextView)

public class MyRadioButton extends AppCompatRadioButton {private float mImg_width;private float mImg_height;public MyRadioButton(Context context) {super(context);}public MyRadioButton(Context context, AttributeSet attrs) {super(context, attrs);TypedArray t = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton);mImg_width = t.getDimension(R.styleable.MyRadioButton_rb_width, DisplayUtil.dp2px(25));mImg_height = t.getDimension(R.styleable.MyRadioButton_rb_height, DisplayUtil.dp2px(25));t.recycle();}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);//让RadioButton的图标可调大小 属性:Drawable drawableLeft = this.getCompoundDrawables()[0];//获得文字左侧图片Drawable drawableTop = this.getCompoundDrawables()[1];//获得文字顶部图片Drawable drawableRight = this.getCompoundDrawables()[2];//获得文字右侧图片Drawable drawableBottom = this.getCompoundDrawables()[3];//获得文字底部图片if (drawableLeft != null) {drawableLeft.setBounds(0, 0, (int) mImg_width, (int) mImg_height);this.setCompoundDrawables(drawableLeft, null, null, null);}if (drawableRight != null) {drawableRight.setBounds(0, 0, (int) mImg_width, (int) mImg_height);this.setCompoundDrawables(null, null, drawableRight, null);}if (drawableTop != null) {drawableTop.setBounds(0, 0, (int) mImg_width, (int) mImg_height);this.setCompoundDrawables(null, drawableTop, null, null);}if (drawableBottom != null) {drawableBottom.setBounds(0, 0, (int) mImg_width, (int) mImg_height);this.setCompoundDrawables(null, null, null, drawableBottom);}}}

3,在xml文件中使用属性控制RadioButton 中的图片大小

<txkj.xian.com.txproject.widget.MyRadioButtonandroid:id="@+id/rb_ali_pay"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:button="@null"app:rb_width="20dp"app:rb_height="20dp"android:layout_centerVertical="true"android:drawableRight="@drawable/selector_radio"android:checked="false"android:clickable="false" />

Android自定义方式设置drawableleft图片大小相关推荐

  1. android thumb大小,Android 设置thumb图片大小

    xml: android:thumb="@drawable/seekbar_thumb" seekbar_thumb.xml: 修改为: private int seekWidth ...

  2. Android 自定义拍照,解决图片旋转,拍照参数设置兼容问题

    Android 自定义拍照,解决图片旋转,拍照参数设置兼容问题 参考文章: (1)Android 自定义拍照,解决图片旋转,拍照参数设置兼容问题 (2)https://www.cnblogs.com/ ...

  3. 如何在Android按钮上以编程方式设置drawableLeft?

    本文翻译自:How to programmatically set drawableLeft on Android button? I'm dynamically creating buttons. ...

  4. android 获取MP4文件的图片大小

    今天,简单讲讲怎么获取MP4视频的每一帧的图片大小. android使用 MediaMetadataRetriever 获取视频文件的 总时长 和视频的分辨率. 根据该方式获取视频信息可以看出不仅仅可 ...

  5. Android自定义相机拍照、图片裁剪的实现

    原文:Android自定义相机拍照.图片裁剪的实现 最近项目里面又要加一个拍照搜题的功能,也就是用户对着不会做的题目拍一张照片,将照片的文字使用ocr识别出来,再调用题库搜索接口搜索出来展示给用户,类 ...

  6. Android 自定义View 圆形圆角图片

    [Android 自定义View 圆形圆角图片] 基于Xfermode 实现 1.概述 在很久以前也写过一个利用Xfermode 实现圆形.圆角图片的(Android 完美实现图片圆角和圆形(对实现进 ...

  7. Android自定义动态布局 — 多图片上传

    Android自定义动态布局 - 多图片上传 本文介绍Android中动态布局添加图片,多图片上传. 项目中效果图:    技术点: 1.动态添加格局中的线条和添加图片的+号 2.多张图片异步上传 首 ...

  8. android 手势事件 重写,Android实现通过手势控制图片大小缩放的方法

    本文实例讲述了Android实现通过手势控制图片大小缩放的方法.分享给大家供大家参考,具体如下: 该程序实现的是通过手势来缩放图片,从左向右挥动图片时图片被放大,从右向左挥动图片时图片被缩小,挥动速度 ...

  9. android自定义view设置高度,自定义View的宽高设定

    关于View的属性 自定义动态设置View的大小属性 使用LayoutParams来设置view的宽高. int textLen = AddShopActivity.mCategoryItemName ...

  10. Android自定义拍照上传界面,Android自定义dialog——设置头像(拍照,相册)

    Android自定义dialog--设置头像(拍照,相册) 需求场景:个人信息设置,点击头像,在界面上弹出一个弹框,用户选择"拍照"/"从图库选择",选择照片后 ...

最新文章

  1. 单例模式 之 单例模式——Holder
  2. python实现图结构github_Github项目+代码:新型深度网络体系结构去除图像中的雨水痕迹...
  3. 【cocos2d-x】瓷砖地图(TileMap)基础知识
  4. Bug调用其他函数失败
  5. 10倍性能提升!DLA SQL推出基于Alluxio的数据湖分析加速功能
  6. php函数scandir_PHP函数glob:扫描目录文件更好的方式
  7. 10大最高效的Java库盘点
  8. 转角遇上Volcano,看HPC如何应用在气象行业
  9. Broken Keyboard(悲剧文本)
  10. 硅谷初创企业控制成本 裁员风渐起
  11. PYTHON之路(九)
  12. 8.input设备(input子系统)驱动
  13. python 处理 图像和视频
  14. 远程手机教学|简单实用,1键远程协助老人使用智能手机
  15. AUTOSAR MCAL解析:MCU
  16. AFN代码解读(-)
  17. TI公司三大系列DSP内部结构之比较
  18. 盘点激光雷达常用的10大数据处理软件
  19. 【Ubuntu】Ubuntu16.04安装GTX960M显卡驱动(960、1070and 750ti直接图形界面安装亲测能用,1080需要到命令界面安装亲测能用)
  20. 设置openwrt,使wifi路由器既可以连接到外网wifi路由器,并且还能够让无线设备来连接。

热门文章

  1. html轮播图片不显示不了,图片轮播的奇怪现象【图片显示不完整】
  2. 4针串口线接法图_串口通信RS232的基本接法,原来这么简单,今天终于弄明白了...
  3. AGV车载控制系统搭建(初学者入门)
  4. Pytorch深度学习实战教程(四):必知必会的炼丹法宝
  5. 魔兽8.0最新服务器人口普查,魔兽世界8.2最新人口普查 2019各服务器人口普查信息汇总...
  6. 笔记本键盘有几个键失灵了怎么办?
  7. python爬虫02 - 爬虫请求模块 request库 json数据
  8. App Store ipv6 审核一直被拒绝
  9. 2017中国产品经理大会总结-我又开始相信可以改变世界了
  10. win10系统下摄像头无法打开的解决方法