Jack
Jack

Reputation: 2053

Increasing performance when loading images from drawable

I am trying to improve the performance in my app when loading 6 large images into an ImageView that are displayed in a GridView.

I know the technique I am using now is awefull.

I have looked at Android's Loading Large Bitmaps Efficiently , but can't get my head round implementing the techniques they use into my code.

Any help would be appreciated.

Here's my class that is used to load the images into the ImageView:

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class AdapterViewADV1 extends BaseAdapter {
private Context mContext;



// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.image_1,
        R.drawable.image_2,
        R.drawable.image_3,
        R.drawable.image_4,
        R.drawable.image_5,
        R.drawable.image_6

};



// Constructor
public AdapterViewADV1(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = null;
    if(convertView == null){
       imageView  = new ImageView(mContext);imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
       imageView.setLayoutParams(new GridView.LayoutParams(NO_SELECTION, NO_SELECTION));
       convertView = imageView;
    }else{
        imageView = (ImageView)convertView;
    }
    imageView.setImageResource(mThumbIds[position]);

    return convertView;
}
}

Upvotes: 0

Views: 1206

Answers (2)

Vikrant_Dev
Vikrant_Dev

Reputation: 390

You can compress your .png images without reducing transparency Click Here to compress

Upvotes: 1

Imtiyaz Khalani
Imtiyaz Khalani

Reputation: 2053

USE IMAGE LOADER it is light weight

Upvotes: 1

Related Questions