[英]Android Universal Image Loader slow, ignores ImageView height and width
I am using the Universal Image Loader library for a multiple image picker to display photos from phone's default gallery in a GridView, it displays all my images but really slow. 我正在使用通用图像加载程序库的多个图像选择器,以在GridView中显示手机默认图库中的照片,它显示了我的所有图像,但速度确实很慢。
I have tried to follow their docs, and set everything to optimise for a quicker image display. 我试图遵循他们的文档,并设置所有内容进行优化以更快地显示图像。 At one point it suggests to set a fixed images size for my ImageView, I am doing so (110dp x 100dp) but it still loads slow and in the log I see that my images have a size of 220 x 240 dp. 有一次它建议为ImageView设置固定的图像大小,我这样做是(110dp x 100dp),但是它仍然加载缓慢,并且在日志中,我看到我的图像的大小为220 x 240 dp。 Why does it ignore my size settings? 为什么它会忽略我的尺寸设置?
To be clear, I would like to optimaize the UIL library with a fixed image size as it shows in the documentation, not to fit the images into my imageview. 明确地说,我想使用文档中显示的固定图像大小优化UIL库,而不是将图像放入我的imageview中。
image item inside gridview: gridview中的图像项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:layout_height="100dp"
android:gravity="center"
android:padding="1dp" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/frmQueue"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imgQueue"
android:layout_width="110dp"
android:layout_height="120dp"
android:contentDescription="@string/app_name"
android:src="@drawable/no_media" />
</FrameLayout>
<ImageView
android:id="@+id/imgQueueMultiSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:background="@drawable/on_focus_checkbox"
android:contentDescription="@string/app_name"
android:gravity="center"
android:scaleType="center"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
settings of the library instance: 库实例的设置:
private void initImageLoader() {
try {
String CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/.temp_tmp";
new File(CACHE_DIR).mkdirs();
File cacheDir = StorageUtils.getOwnCacheDirectory(getBaseContext(), CACHE_DIR);
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheOnDisc(true).imageScaleType(ImageScaleType.IN_SAMPLE_INT).bitmapConfig(Bitmap.Config.RGB_565).build();//.cacheInMemory(true)
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(getBaseContext()).threadPoolSize(3).defaultDisplayImageOptions(defaultOptions).discCache(new UnlimitedDiscCache(cacheDir)).memoryCache(new WeakMemoryCache());
ImageLoaderConfiguration config = builder.build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
//L.disableLogging();
} catch (Exception e) {}
}
private void initImageLoader() {
DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
.showImageOnFail(R.drawable.default_img)
.showImageOnLoading(R.drawable.default_img)
.cacheOnDisk(true).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCacheSize(20 * 1024 * 1024) // 20 Mb
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiscCache(getCacheDir()))
.diskCacheSize(20 * 1024 * 1024) //20 Mb
.tasksProcessingOrder(QueueProcessingType.LIFO)
//.enableLogging() // Not necessary in common
.defaultDisplayImageOptions(displayImageOptions)
.threadPoolSize(30)
.build();
com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config);
}
This is my configuration, Please try to replicate it once. 这是我的配置,请尝试复制一次。 This is working fine for me. 这对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.