我使用Glide (4.6.1) 将图像从 url 加载到RecyclerView,与 Amazon 或 Flipkart 等应用程序相比,它非常慢,我的每个图像大小约为170 KB。我不想使用缓存,因为我不会得到动态响应。有什么办法可以让图片加载更快。
public static void setGlide(Context context, ImageView imageView, String imageLink) {
RequestOptions requestOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.centerCrop()
.dontAnimate()
.dontTransform()
.placeholder(R.drawable.error_logo)
.priority(Priority.IMMEDIATE)
.encodeFormat(Bitmap.CompressFormat.PNG)
.format(DecodeFormat.DEFAULT);
Glide.with(context)
.applyDefaultRequestOptions(requestOptions)
.load(imageLink")
.error(Glide.with(context)
.load(R.drawable.error_logo))
.into(imageView);
Glide.get(context).clearMemory();
}
Run Code Online (Sandbox Code Playgroud)
build.gradle依赖项是
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}
Run Code Online (Sandbox Code Playgroud)