9

I am trying to insert a generic loading circle as placeholder while an image is being loaded with an image loader library like Glide or Picasso.

I cannot for the life of me find out how you are supposed to create a rotating drawable from xml.

I tried using an AnimationDrawable in XML by creating an animation-list, but it doesn't even show up (not even static).

I just want to have a simple circle that spins all by itself, all in an xml drawable, so I can pass the id as placeholder to my image loader. If that is not possible please tell me now, so I can save a lot of research :)

EDIT: Some code to make it more clear, I need a spinning drawable for this Glide command:

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

While the image is being loaded a placeholder drawable will be shown where the image will later be. I need a drawable that spins itself.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
A. Steenbergen
  • 3,360
  • 4
  • 34
  • 51
  • 2
    May a topic https://github.com/bumptech/glide/issues/505 will help? – CoolMind Aug 10 '16 at 06:21
  • 1
    Hey CoolMind, thanks for the answer! I am not sure, since this question is years old, but thanks for pointing me into the right direction, it looks useful, maybe I will come back to your answer some day and it certainly helps others – A. Steenbergen Aug 10 '16 at 09:18
  • A. Steenbergen, thanks! I understand that too much time have past, sorry. I have not this problem but recently had a problem with ProgressBar visibility (solved with http://stackoverflow.com/a/38849129/2914140). Also want to attach these links: http://stackoverflow.com/questions/35305875/progress-bar-while-loading-image-using-glide and https://github.com/bumptech/glide/issues/232. – CoolMind Aug 10 '16 at 09:52

2 Answers2

0

You can add a ProgressBar element to your layout XML, and then display/hide this element as needed. The ProgressBar View is built in and already animated, no custom AnimationDrawable required.

eshayne
  • 915
  • 9
  • 15
  • 2
    Thanks, but this is not what I need. I am using bumbtech's glide image loading library to load a list of images from a server, while the images are loading a placeholder drawable is shown for every image where the real image will later be. I want this placeholder to be an animated spinning circle to indicate that the image is loading and for that I need this spinning circle to be a single drawable, no extra code like object animators or animations in code. I added some code to make it more clear. – A. Steenbergen Sep 16 '14 at 17:33
  • 2
    Did you ever get a solution to this concern Doge? Also in a bind looking for this... – Marka A Apr 08 '15 at 00:36
0

You can use something like this:

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);
        }
    });