首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用Glide加载图像时的进度条

使用Glide加载图像时的进度条
EN

Stack Overflow用户
提问于 2016-02-10 10:34:26
回答 5查看 103.3K关注 0票数 118

在使用Glide加载图像之前,我可以使用旋转动画加载占位符中的微调器吗?

我正在尝试使用.placeholder(R.Drawable.spinner)来做这件事,没有动画吗?

如果有人能帮我就太好了?

谢谢!

EN

回答 5

Stack Overflow用户

发布于 2018-05-18 02:50:46

我正在用Kotlin编写一个应用程序,遇到了这个问题,但不幸的是,公认的答案是Java。所以,我用Kotlin重写了它。

代码语言:javascript
复制
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)
票数 15
EN

Stack Overflow用户

发布于 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文件

代码语言:javascript
复制
<?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

代码语言:javascript
复制
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)最后使用它加载图片,如下所示

代码语言:javascript
复制
Glide.with(this).load(//*Your image url*//).apply(options).into(image_view);
票数 10
EN

Stack Overflow用户

发布于 2020-01-11 07:13:37

这是我的完整解决方案,其中包含一个循环加载进度。我认为最好使用requestOptions属性来实现这一点。

代码语言:javascript
复制
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.

你得到了它。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35305875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档