我正在尝试使用Glide.But Glide.listener()加载图片后隐藏进度条。请找到以下代码。
@BindingAdapter({
"bind:url"
})
public void setImage(ImageView imageView, String url) {
if (url != null && url.trim().length() > 0) {
Glide.with(imageView.getContext()).load("http://" + url)
.override(200, 150)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
bindFamilyMembers.imagebar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
bindFamilyMembers.imagebar.setVisibility(View.GONE);
return false;
}
})
.placeholder(R.drawable.bg_theme)
.error(R.drawable.bg_theme)
.into(imageView);
// Picasso.with(imageView.getContext()).load("http://" + url).resize(200, 150).error(R.drawable.ic_launcher_background).into(imageView);
} else {
}
}
此代码的布局如下。我在我的应用程序中使用数据绑定。我尝试使用数据绑定将可见性设置为Gone,但它无效。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="familyhandler"
type="com.estuate.smartfoam.dashboard.model.apiuser.FamilyMembers" />
</data>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rel"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.estuate.smartfoam.util.CircularImageView
android:id="@+id/member_image"
android:layout_width="120dp"
android:layout_marginTop="@dimen/linear_margin_10"
android:layout_height="100dp"
app:url="@{familyhandler.image}" />
<ImageView
android:id="@+id/border"
android:layout_width="120dp"
android:layout_height="120dp"
android:visibility="gone"
android:background="@drawable/circular_img_selected" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{familyhandler.fullname}"
android:textColor="@color/blackColor"
android:textAllCaps="true"
android:layout_below="@id/member_image"
android:textSize="@dimen/text_size_16"
tools:text="Name"
android:layout_centerHorizontal="true" />
<ProgressBar
android:id="@+id/imagebar"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@xml/progress"
android:visibility="visible"
android:layout_centerInParent="true" />
</RelativeLayout>
<ImageView
android:id="@+id/adding_view"
android:layout_width="110dp"
android:layout_height="100dp"
android:layout_marginTop="@dimen/linear_margin_15"
android:visibility="gone"
android:src="@drawable/ic_add_material"
android:background="@drawable/circular_add" />
</LinearLayout>
</layout>
我使用Glide来解析图像。但是无法阻止进度条。你可以帮我解决这个问题。
答案 0 :(得分:0)
如果ImageView的可见性不可见或消失,这似乎是一个错误。我在这里打开了一个问题:https://github.com/bumptech/glide/issues/618