Sre*_*ree 0 android android-glide
我在这里做错什么了吗?我想加载该灰色作为占位符,但是它不加载。似乎只有在已经设置或加载了另一个图像的情况下才会发生。
Glide.with(getContext())
.load(url)
.placeholder(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
.error(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
.dontAnimate()
.into(new SimpleTarget<GlideDrawable>() {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
image.setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
resetImageView();
}
});
Run Code Online (Sandbox Code Playgroud)
试试下面的代码:
滑行版本:
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"></ImageView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Java代码:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Glide.with(this)
.load("http://matplotlib.org/_images/color_demo.png")
.placeholder(new ColorDrawable(ContextCompat.getColor(MainActivity.this, R.color.placeholder_gray)))
.error(new ColorDrawable(ContextCompat.getColor(MainActivity.this, R.color.placeholder_gray)))
.dontAnimate()
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
颜色(在colors.xml中)
<color name="placeholder_gray">#A9A9A9</color>
Run Code Online (Sandbox Code Playgroud)
尝试使用有效的URL和无效的URL。对于有效URL,在加载图像之前会显示灰色,对于无效URL,则会显示灰色占位符。
| 归档时间: |
|
| 查看次数: |
2584 次 |
| 最近记录: |