你如何使用加载占位符作为动画微调器与像Glide,毕加索等图像加载器?

问题描述 投票:9回答:2

我正在尝试插入一个通用加载圈作为占位符,同时图像正在加载像Glide或Picasso这样的图像加载器库。

我不能为我的生活找到你应该如何从xml创建一个旋转drawable。

我尝试通过创建动画列表在XML中使用AnimationDrawable,但它甚至没有显示(甚至不是静态的)。

我只想要一个简单的圆圈,它可以自动旋转,所有这些都在xml drawable中,所以我可以将id作为占位符传递给我的图像加载器。如果那不可能请现在告诉我,所以我可以节省很多研究:)

编辑:一些代码使它更清晰,我需要一个旋转drawable这个Glide命令:

Glide.with(context)
.load(imageUrl)
.into(imageView)
.placeHolder(R.drawable.spinning_loading_placeholder);

在加载图像时,将显示占位符drawable,稍后将显示图像。我需要一个能够自行旋转的抽屉。

android animation spinner drawable android-glide
2个回答
0
投票

您可以将ProgressBar元素添加到布局XML,然后根据需要显示/隐藏此元素。 ProgressBar View内置并已动画,无需自定义AnimationDrawable。


0
投票

你可以使用这样的东西:

Glide.with(mContext).load(imageUrl).asBitmap().centerCrop().into(new BitmapImageViewTarget(vh.avatarImageView) {

        @Override
        public void onLoadStarted(Drawable placeholder) {
                vh.avatarImageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_placeholder));
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            vh.avatarImageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_failed_download));
        }

        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable =
                    RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            vh.avatarImageView.setImageDrawable(circularBitmapDrawable);
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.