Gridview with universal image loader images are loading slowly

711 Views Asked by At

i'm using universal image loader to populate thumbnails into gridview from assets gallary but images are loading slowly during scrolling up or down so i think because images are being loaded with it's current resolution so how i can change the resolution of the images for example i used to use createScaledBitmap to scale down the bitmap Here is my code :

public class ImageAdapter extends BaseAdapter {
private Context mContext;
private List<String> mList;
private int mheight;
private int mwidth;
private InputStream is;
private HomePage homePage;
private ImageLoader imageLoader;




public ImageAdapter(Context context, List<String> list, int height, int width) {
    mContext = context;
    mList = list;
    mheight = height;
    mwidth = width;
    ImageLoader imageLoader = ImageLoader.getInstance();
    this.imageLoader = imageLoader;

}


@Override
public int getCount() {
    return mList.size();
}

@Override
public Object getItem(int position) {
    return mList.get(position).toString();
}

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





@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {
        imageView = new ImageView(mContext);
    } else {
        imageView = (ImageView) convertView;
    }


    File cacheDir = new File(Environment.getExternalStorageDirectory(),    "UniversalImageLoader/Cache");
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
   .threadPoolSize(5)
   .memoryCacheExtraOptions(mwidth/3, mwidth/3)
   .threadPriority(Thread.MIN_PRIORITY )
    .memoryCache(new UsingFreqLimitedMemoryCache(5000000)) // You can pass your own memory cache implementation
    .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
    .build();

    imageLoader.init(config);
 //
 //
    //display options
    DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.loading)
    .showImageForEmptyUri(R.drawable.loading)
    .cacheInMemory()
    .cacheOnDisc() 
    .bitmapConfig(Bitmap.Config.RGB_565)
    .imageScaleType(ImageScaleType.EXACTLY)
    .build();

//        // Create configuration for ImageLoader

    String imString = mList.get(position);
    String imageUria = "assets://"+imString;

   imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
   imageView.setLayoutParams(new GridView.LayoutParams(mwidth/3, mwidth/3));
   imageLoader.displayImage(imageUria, imageView ,options );
     return imageView ;

} }

0

There are 0 best solutions below