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

使用软引用设置背景

2013年10月26日 ⁄ 综合 ⁄ 共 442字 ⁄ 字号 评论关闭
imageView = (ImageView) findViewById(R.id.sItemIcon);
	imageView.setBackgroundDrawable(loadDrawable(R.drawable.id));
	//软引用设置
	private Map<Integer, SoftReference<Drawable>> imageCache 
				= new HashMap<Integer, SoftReference<Drawable>>();
	private Drawable loadDrawable(Integer id){
		if(imageCache.containsKey(id)){
			Drawable d=imageCache.get(id).get();
			if(d!=null)return d;
		}
		Drawable d=getResources().getDrawable(id);
		imageCache.put(id, new SoftReference<Drawable>(d));
		return d;
	}

抱歉!评论已关闭.