【发布时间】:2019-02-14 12:21:48
【问题描述】:
我有一个 viewPager 有 4 个需要调整大小的图像。我实现了不同的选项,但没有选项运行。我写了不同的选项:
-
在 getView 中放置:
image.setImageBitmap(bitmap);位图获取:
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);
但是速度很慢。
我把最后一段代码放在了 AsyncTask() 中,但是我不能快速滚动。
-
我覆盖了
onPageScrollStateChange(int state)我只在状态为
SCROLL_STATE_IDLE时显示图像,但效果与其他情况相同。 -
我使用 LruCache,我将图像保存在 Asynctask 中的 LruCache 中。
我在instanceiteItem中放了for(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);
但问题与上一个案例相同,我无法快速滚动,应用程序也很慢。
我有质量和尺寸都很大的图像。如何在 viewPager 中快速滚动?
【问题讨论】:
标签: android android-asynctask android-viewpager image-resizing android-lru-cache