-------因爲項目中用到了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();
-----今天記錄下,明天再研究吧