现在的位置: 首页 > 综合 > 正文

Android学习札记17:ImageView中的setImageBitmap()方法

2017年12月17日 ⁄ 综合 ⁄ 共 718字 ⁄ 字号 评论关闭

在4.0.4 r1.2中查看android.widget.ImageView源代码可以发现,setImageBitmap()方法其实是调用了setImageDrawable()方法进行重绘。


Sets a Bitmap as the content of this ImageView.

Parameters:
bm The bitmap to set

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) {
	// if this is used frequently, may handle bitmaps explicitly
	// to reduce the intermediate drawable object
	setImageDrawable(new BitmapDrawable(mContext.getResources(), bm));
}

Sets a drawable as the content of this ImageView.

Parameters:
drawable The drawable to set

public void setImageDrawable(Drawable drawable) {
	if (mDrawable != drawable) {
		mResource = 0;
		mUri = null;

		int oldWidth = mDrawableWidth;
		int oldHeight = mDrawableHeight;

		updateDrawable(drawable);

		if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeigh{
			requestLayout();
		}
		invalidate();
	}
}

抱歉!评论已关闭.