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;
}
使用软引用设置背景
最新推荐文章于 2022-11-29 16:41:44 发布