android setBackgroundDrawable setImageBitmap 区别
-------因为项目中用到了ImageView 在代码中动态加载网络图片,但是加载过来的图片有时候带一块透明的区域(占空间,属于背景)
后来虽然解决了用的方法如下:
if(ReasonResultActivity.m_width<=480){
holder.imageView.setBackgroundDrawable(bd);
}else{
holder.imageView.setImageBitmap(bm);
}
ReasonResultActivity.m_width是获取到的设备的宽度的分辨率。
虽然解决了但是还不是很明白,于是找了些资料,如下,看了之后也不是很懂其中的道理。
一、setBackgroundXXX的用处,设置这个View背景。
setBackgroundDrawable 的参数为Drawable对象,
setBackgroundColor 的参数为Color对象,比如说Color.Red为红色,或Color.rgb(255,0,0) 来制定一个红色
setBackgroundResource 的参数为资源ID,比如说R.drawable.icon
二、对于ImageView类有类似 setImageXXX
道理同上,setImageBitmap的参数为Bitmap对象,同时ImageView还支持矩阵对象,比如setImageMatrix的参数为Matrix对象。
bimap和BitmapDrawable的转换:
一、Bitmap转Drawable Bitmap bm=xxx; //xxx根据你的情况获取
BitmapDrawable bd=new BitmapDrawable(bm);
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
-----今天记录下,明天再研究吧
更多相关文章
- 《Android》Lesson20-广播2
- Android(安卓)Activity间切换动画效果
- android tween 四种动画
- Android(安卓)- 实现各种形状的ImageView
- Android(安卓)输入系统(一)InputManagerService
- Android中文API(145) —— NotificationManager
- android native jni 代码
- Android(安卓)Java笔试题(带大部分答案)
- Android(安卓)WebView如何加载assets下的html文件