Android动态设置android:drawableLeft|Right|Top|Bottom 并根据分辨率自适应
16lz
2021-01-25
http://blog.sina.com.cn/s/blog_4b93170a0102e1m9.html
//调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示 最主要一点,不然不显示图片,搞了半天
/** * 从png文件得到Bitmap * 并且将尺寸调整为宽=w、高=h */ public static Bitmap getMyBitmap(String imageName, int w, int h){ String filePath = IMAGE_PATH + "/" + imageName + ".png"; Bitmap oldbmp = BitmapFactory.decodeFile(filePath); if(oldbmp!=null){ int width = oldbmp.getWidth(); int height = oldbmp.getHeight(); 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; } }
调整分辨率
http://blog.sina.com.cn/s/blog_4607d856010125sl.htmlBitmapDrawable的使用转换
更多相关文章
- android 内存泄露--加载网络图片--android 12742656-byte extern
- android在原来的view上画边框或者其它内容
- AAPT err... ERROR: Unable to open PNG file的解决方案
- [置顶] 自定义漂亮的Android(安卓)SeekBar样式
- android 防止bitmap 内存溢出
- 屏幕适配问题
- 相机的研究
- Android(安卓)关于微信分享图片过大失败的解决方案
- Android中为edittext预设文字(使用hint)