I have a viewPager that have 4 images that need to resize. I implemented different options but no options run. I write the different options:
In getView put:
image.setImageBitmap(bitmap);
The bitmap obtain:
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(bitmapOriginal, null, options); int sampleSize = 1; while ((options.outHeight > 600 * sampleSize) &&(options.outWidth > 400 * sampleSize)) { sampleSize *= 2; } options.inJustDecodeBounds = false; options.inMutable = false; options.inSampleSize = sampleSize; Bitmap bm=BitmapFactory.decodeStream(bimapOriginal, null, options);
But it's very slowly.
I put the last code in AsyncTask() but I can't scroll quickly.
I override the
onPageScrollStateChange(int state)
I only show the image when the state is
SCROLL_STATE_IDLE
but the effect is the same as in the other cases.I use LruCache, I save the images in LruCache in Asynctask.
In instantiateItem I putfor(int i=position *4;i<(position +1)*4 +4;i++) { //NameImage is an Array with the name of image. Every time that calling instantiateItem save 4 images in LruCache new BitmapWorkerTask(nameImage[i).executorOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
But the problem is the same as last cases, I can't scroll quickly and the app are so slowly.
I have images with a big quality and size. How can I do to scroll quickly in viewPager?