ImageSwitcher slide animation not work when use glide to load

399 Views Asked by At

ImageSwitcher slide animation not work when use glide to load.

imageSwitcher.setInAnimation(In);
imageSwitcher.setOutAnimation(Out);
Glide
     .with(getActivity())
     .load(imageURL)
     .into((ImageView) imageSwitcher.getCurrentView());

This animation works fine when load image form local resource without glide

imageSwitcher.setImageResource(data.get(position).getImage_drawable());
1

There are 1 best solutions below

1
On

Just use it like this:

Glide.with(view.context)
            .asDrawable()
            .load(url)
            .listener(object : RequestListener<Drawable> {
                override fun onLoadFailed(
                    e: GlideException?,
                    model: Any?,
                    target: Target<Drawable>?,
                    isFirstResource: Boolean
                ) = false

                override fun onResourceReady(
                    resource: Drawable?,
                    model: Any?,
                    target: Target<Drawable>?,
                    dataSource: DataSource?,
                    isFirstResource: Boolean
                ): Boolean {
                    (view.nextView as? ImageView)?.setImageDrawable(resource)
                    view.showNext()
                    return true
                }
            })
            .submit()