gpt4 book ai didi

java - 如果使用 .asBitmap(), Glide 监听器不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:57 30 4
gpt4 key购买 nike

在一个android项目中,我有这段代码来获取ImageView中的图像

xml

<package.RoundedImageView
android:id="@+id/options_photo_icon"
android:layout_width="@dimen/registration_icons_height"
android:layout_height="@dimen/registration_icons_height"
android:maxWidth="@dimen/registration_icons_height"
android:maxHeight="@dimen/registration_icons_height"
android:src="@drawable/no_image"
android:foregroundGravity="center"
android:layout_centerHorizontal="true"
android:layout_weight="1" />

java

Glide
.with(context)
.load(url)
.asBitmap()
.centerCrop()
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
//do something
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
//do somethig else.
return false;
}
})
.into(options_photo_icon);

但我收到此错误:

Error:(212, 21) error: no suitable method found for listener(>) method GenericRequestBuilder.listener(RequestListener) is not applicable (argument mismatch; > cannot be converted to RequestListener) method BitmapRequestBuilder.listener(RequestListener) is not applicable (argument mismatch; > cannot be converted to RequestListener)

如果我删除 as .asBitmap() 我不会收到错误,但我需要 .asBitmap() 来做其他事情。如果我是 asBitmap ,我不能使用监听器吗?

最佳答案

试试这个

SimpleTarget target = new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
imageView.setImageBitmap(resource);
}
};
Glide.with(getApplicationContext()).load(profileUrl)
.asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.profile_placeholder)
.error(R.drawable.profile_placeholder).into(target);

关于java - 如果使用 .asBitmap(), Glide 监听器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128925/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com