在使用Glide加载图像之前,我可以使用旋转动画加载占位符中的微调器吗?
我正在尝试使用.placeholder(R.Drawable.spinner)来做这件事,没有动画吗?
如果有人能帮我就太好了?
谢谢!
发布于 2018-05-18 02:50:46
我正在用Kotlin编写一个应用程序,遇到了这个问题,但不幸的是,公认的答案是Java。所以,我用Kotlin重写了它。
Glide.with(context)
.load("<Insert Your URL>")
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
progressBar.visibility = View.GONE
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
progressBar.visibility = View.GONE
return false
}
})
.into(holder.imageView)
发布于 2019-04-11 20:30:25
是的,我们可以使用Glide RequestOptions在ImageView上显示加载器。
1)在app级gradle文件中使用下面的编译行。
implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
2)在可绘图中添加progress_animation.xml文件
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loader_test"
android:pivotX="50%"
android:pivotY="50%"/>
3)在drawable中添加下面的loader_test.png图像
4)如下所示创建RequestOption
public RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.drawable.progress_animation)
.error(R.drawable.user_image)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.dontAnimate()
.dontTransform();
5)最后使用它加载图片,如下所示
Glide.with(this).load(//*Your image url*//).apply(options).into(image_view);
发布于 2020-01-11 07:13:37
这是我的完整解决方案,其中包含一个循环加载进度。我认为最好使用requestOptions
属性来实现这一点。
CircularProgressDrawable circularProgressDrawable = new CircularProgressDrawable(context);
circularProgressDrawable.setStrokeWidth(5f);
circularProgressDrawable.setCenterRadius(30f);
circularProgressDrawable.start();
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(circularProgressDrawable);
requestOptions.error(R.drawable.ic_image_not_found);
requestOptions.skipMemoryCache(true);
requestOptions.fitCenter();
glide.load(imagePath) //passing your url to load image.
.load(imagePath)
.apply(requestOptions) // here you have all options you need
.transition(DrawableTransitionOptions.withCrossFade()) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.listener(requestListener)
.into(view); //pass imageView reference to appear the image.
你得到了它。
https://stackoverflow.com/questions/35305875
复制相似问题