标签:android
代码实现方式:(布局的背景图较大,可能在内存吃紧的时候造成oom或者奔溃,以最省内存的方式读取本地资源的图片)
relativeLayout_getprize = (RelativeLayout) findViewById(R.id.relativeLayout_getprize);
Bitmap readBitMap = BitmapUtil.readBitMap(this, R.drawable.zjbj);
Drawable drawable = new BitmapDrawable(readBitMap);
relativeLayout_getprize.setBackgroundDrawable(drawable);
工具类用到:
/**
* 以最省内存的方式读取本地资源的图片
* @param context
* @param resId
* @return
*/
public static Bitmap readBitMap(Context context, int resId) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
// 获取资源图片
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is, null, opt);
}
标签:android
原文地址:http://blog.csdn.net/u014074418/article/details/44964057