我希望将视图引用指定为
然而我的进度视图为空。 我尝试将上下文转换为活动(Activity),并使用findViewById,但结果仍为空。 另一个解决方案是在图片下方添加进度视图,在图片成功加载后应该覆盖它。
ImageView
的属性。@BindingAdapter(value = {"imageUrl", "progressView"}, requireAll = false)
public static void setImageUrl(ImageView imageView, String url, @IdRes int progressBar) {
Context context = imageView.getContext();
View progressView = imageView.getRootView().findViewById(progressBar);
progressView.setVisibility(View.VISIBLE);
Glide.with(context).load(url).listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
if (progressView!= null) {
progressView.setVisibility.setVisibility(View.GONE);
}
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
if (progressView!= null) {
progressView.setVisibility(View.GONE);
}
return false;
}
}).crossFade().into(imageView);
}
然而我的进度视图为空。 我尝试将上下文转换为活动(Activity),并使用findViewById,但结果仍为空。 另一个解决方案是在图片下方添加进度视图,在图片成功加载后应该覆盖它。