Android 滑动4.7.1占位符未加载
我正在尝试使用GlideLibrary和SimpleTarget加载占位符图像。占位符图像未加载,但url中的图像正在加载。我搜索了很多,也使用了RequestOptions。不过,它似乎不起作用 代码如下:Android 滑动4.7.1占位符未加载,android,placeholder,android-glide,Android,Placeholder,Android Glide,我正在尝试使用GlideLibrary和SimpleTarget加载占位符图像。占位符图像未加载,但url中的图像正在加载。我搜索了很多,也使用了RequestOptions。不过,它似乎不起作用 代码如下: Glide.with(mContext).load("https://i.imgur.com/0k7ZFWr.png").apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon)).into(new SimpleTarget
Glide.with(mContext).load("https://i.imgur.com/0k7ZFWr.png").apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon)).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.cardImageLayout.setBackground(resource);
Drawable cardViewBackground = holder.cardImageLayout.getBackground();
cardViewBackground.setColorFilter(0x5F000000, PorterDuff.Mode.SRC_ATOP);
}
}
});
Glide.with(mContext).load(“https://i.imgur.com/0k7ZFWr.png将(RequestOptions.placeholder of(R.drawable.pugguide_icon))应用到(new SimpleTarget()中{
@凌驾
public void onResourceReady(可提取资源,转换)
的占位符只在将占位符图像加载到图像视图中时设置占位符图像。如果要将占位符设置为视图组,SimpleTarget
类提供了一种方法,可以在图像开始加载时覆盖该方法以设置背景。
在您的情况下,请尝试按如下方式加载:
Glide.with(mContext)
.load("https://i.imgur.com/0k7ZFWr.png")
.apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon))
.into(new SimpleTarget<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable resource) {
holder.cardImageLayout.setBackground(resource);
}
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.cardImageLayout.setBackground(resource);
Drawable cardViewBackground = holder.cardImageLayout.getBackground();
cardViewBackground.setColorFilter(0x5F000000, PorterDuff.Mode.SRC_ATOP);
}
}
});
Glide.with(mContext)
.加载(“https://i.imgur.com/0k7ZFWr.png")
.apply(RequestOptions.placeholder of(R.drawable.pugguide_图标))
.into(新的SimpleTarget(){
@凌驾
public void onload已启动(@Nullable Drawable resource){
支架.布局.立根点(资源);
}
@凌驾
public void onResourceReady(@NonNull Drawable resource,Transition您可以通过Glide(4.7.1)实现这一点)
你实际上想做什么..加载占位符直到图像没有正确加载?
Glide.with(mContext)
.load("https://i.imgur.com/0k7ZFWr.png")
.apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon))
.into(new SimpleTarget<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable resource) {
holder.cardImageLayout.setBackground(resource);
}
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.cardImageLayout.setBackground(resource);
Drawable cardViewBackground = holder.cardImageLayout.getBackground();
cardViewBackground.setColorFilter(0x5F000000, PorterDuff.Mode.SRC_ATOP);
}
}
});
Glide.with(getActivity()).load(avatar)
.apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.defaultusericon))
.into(mUserIcon);