recycle Image View - Android User Interface

Android examples for User Interface:RecyclerView

Description

recycle Image View

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;

import android.widget.ImageView;

public class Main {

    public static void recycleImageView(View view) {
        if (view == null)
            return;
        if (view instanceof ImageView) {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable instanceof BitmapDrawable) {
                Bitmap bmp = ((BitmapDrawable) drawable).getBitmap();
                if (bmp != null && !bmp.isRecycled()) {
                    ((ImageView) view).setImageBitmap(null);
                    bmp.recycle();/*from   w  w w .jav  a 2s . c o  m*/
                    bmp = null;
                }
            }
        }
    }
}

Related Tutorials