我正在尝试一个简单的测试。
MainActivity.java
public class MainActivity extends AppCompatActivity {
private static final int N = 20;
private final List<ImageView> images = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridLayout root = ((GridLayout) findViewById(R.id.root));
for (int i = 0; i < N; i++) {
ImageView image = new ImageView(this);
images.add(image);
root.addView(image, 100, 100);
}
findViewById(R.id.load).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
load();
}
});
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build()
);
load();
}
private void load() {
for (int i = 0; i < images.size(); i++)
Glide.with(this).load("https://dummyimage.com/100x100/000/fff&text=" + (i + 1)).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).priority(Priority.IMMEDIATE).into(images.get(i));
}
}
MyGlideModule.java
public class MyGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
}
@Override
public void registerComponents(Context context, Glide glide) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
client.addInterceptor(logging);
client.addNetworkInterceptor(new StethoInterceptor());
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client.build());
glide.register(GlideUrl.class, InputStream.class, factory);
}
}
问题是图像是一张一张地加载的,尽管我希望它们会同时加载。
它很好地显示在 Chrome 网络跟踪中(感谢 Stetho)
是否可以让 glide 一次开始加载所有图像?