Radiobutton 设置drawtop图片大小
来源:互联网 发布:java中间件启动spring 编辑:程序博客网 时间:2024/05/16 05:55
首先从资源文件中获取图片资源
//获取资源文件图片,设置大小 public static Bitmap getMyBitmap(Context context, int id,int w, int h){ Bitmap oldbmp = BitmapFactory.decodeResource(context.getResources(), id); if(oldbmp!=null){ int width = oldbmp.getWidth();//获取的是像素 int height = oldbmp.getHeight(); Log.i("单位", "宽:"+width+"高度:"+height); Matrix matrix = new Matrix(); float scaleWidth = ((float) w / width); float scaleHeight = ((float) h / height); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); return newbmp; } else{ return null; }}单位转换工具类
import android.content.Context; public class DensityUtil { /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */ public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } }
实现代码
radio_first = (RadioButton) findViewById(R.id.radio_first);int sp=DensityUtil.dip2px(this, 30);//转换为像素 Log.i("单位", "转换的像素:"+sp);Drawable dr_first=new BitmapDrawable( Utils.getMyBitmap(this, R.drawable.nav_yi,sp , sp));//位图转换为drawabledr_first.setBounds(0, 0, dr_first.getMinimumWidth(), dr_first.getMinimumHeight()); radio_first.setCompoundDrawables(null,dr_first,null , null);//radioabutton 设置但是我建议不要使用这种方法,美工能把图片做到最适合的尺寸,就最好,这种模式性能不高,而且很难设置适合的放大缩小比例。
0 0
- Radiobutton 设置drawtop图片大小
- android 修改RadioButton的drawTop图片大小
- RadioButton的图片大小设置
- radioButton图片大小的设置
- 如何给RadioButton设置图片大小
- 安卓 RadioButton的图片大小设置 draw的图片大小设置
- 通过代码设置改变radiobutton图片大小
- 在代码中设置RadioButton中图片大小
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- 设置Android中RadioButton的图片大小和位置
- 利用RadioGroup嵌套RadioButton实现Android主页面底部导航栏动态设置图片大小
- RadioButton图片居中and修改图片大小
- RadioButton动态改变drawableTop的图片大小
- Android 调整 TextView,CheckBox,RadioButton中图片大小
- word 批量设置图片大小
- ewebeditor上传图片大小设置
- 如何利用DBMS_LOGMNR包挖掘在线日志
- 密码安全与加密-提升千百倍的密码安全
- MySQL 不能插入中文和显示中文
- C++调用C
- 从system返回值中获得程序退出码
- Radiobutton 设置drawtop图片大小
- IOS学习 ARC下__bridge
- RobotFramework+Selenium2的入门与提高
- 翻译:Linux的电源管理架构
- Android scroll的封装器Scroller (一)
- Qt5.4 安装包的区别及配置调试器的问题
- iOS学习笔记09—iOS并发编程
- 使用cordova3.5(phoneGap)打包发布程序备忘
- 对软件开发人员的几个阶段思考和总结