使用软引用设置背景

来源:互联网 发布:windows 10 蓝牙丢失 编辑:程序博客网 时间:2024/06/03 19:36
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;}

原创粉丝点击