我想将视图引用指定为属性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);
}
但是我的进度视图为空。我尝试将上下文转换为活动,并且findViewById
还为空另一个解决方案只是在图像下方添加进度视图,当它成功加载时,它应该被覆盖 bt 图像