[Android Memory] 手动回收ImageVIew的图片资源

ImageView默认是不进行图片资源的回收的,需要我们自己在activity或者fragment中进行回收:

public static void releaseImageViewResouce(ImageView imageView) {
        if (imageView == null) return;
        Drawable drawable = imageView.getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap != null && !bitmap.isRecycled()) {
                bitmap.recycle();
            }
        }
    }

 

posted @ 2014-09-03 19:17  demoblog  阅读(15002)  评论(1编辑  收藏  举报