我最近更新了我的应用程序,使用Glide4,准确地说,Glide4.2.0。
等级:

compile 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
compile ('com.github.bumptech.glide:okhttp3-integration:4.2.0'){
    exclude group: 'glide-parent'
}

在清单中:
<meta-data
            android:name="com.xxx.MyGlideModule"
            android:value="GlideModule"/>

滑翔舱等级:
@GlideModule
public class MyGlideModule extends AppGlideModule {

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .connectTimeout(30, TimeUnit.SECONDS)
                .build();

        OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);

        glide.getRegistry().replace(GlideUrl.class, InputStream.class, factory);
    }
}

如何在适配器中使用glide:
        RequestOptions myOptions = new RequestOptions()
                .placeholder(R.drawable.ic_placeholder)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .dontAnimate()
                .skipMemoryCache(true)
                ;

        Glide.with(mContext)
                .load(Imageid[position])
                .apply(myOptions)
                .into(imageView);

有了这些代码,当我运行它时,我得到了错误:
java.lang.RuntimeException: Expected instanceof GlideModule, but found: [my app package].MyGlideModule@d1c2328
  at com.bumptech.glide.module.ManifestParser.parseModule(ManifestParser.java:81)
  at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:43)
  at com.bumptech.glide.Glide.initializeGlide(Glide.java:193)
  at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:172)
  at com.bumptech.glide.Glide.get(Glide.java:156)
  at com.bumptech.glide.Glide.getRetriever(Glide.java:540)
  at com.bumptech.glide.Glide.with(Glide.java:566)
  at [adapter line where I implement Glide]

如何使用我的滑翔模块?

最佳答案

glide 4.0不需要在androidmanifest.xml中声明“glidemodule”。您只需执行以下步骤:
你的glidemodule扩展了appglidemodule,你可以重写glidemodule类中的函数。
您应该在“android studio->build->make project”中创建project,它将生成applyOptions类。
使用glideapp,例如GlideApp

08-18 09:22