Nick Nick - 1 year ago 63
Android Question

Android: Update ImageView Background while Behind other ImageView

I'm building an app where I want to swipe images as though they were photos on a stack. In other words, if I swipe the top image I want it to animate moving in the direction of the swipe and have the next image underneath it visible the whole time. To accomplish this, I'm using a

and two
containers. I'm just alternating which one is on top. Meanwhile, as soon as a swipe occurs, the next image is loaded into the
at the back using
. My problem is that the
at the back doesn't update it's image until I call
on it, which means that as the top
is animating, the image underneath is incorrect until the animation completes, at which point it abruptly changes to the correct image. I've tried calling
on the rear
but this doesn't work. Anyone have any ideas on how I can get the image to update while it's behind?

UPDATE: Turns out I'm just not very on it today. I was updating the wrong
and because the image loading was being done off the network, there was just enough lag to make me think it was happening after the animation completed.

Answer Source

Sounds to me like you wanna do something like an Image Slider.

There are great libraries existing for this purpose, this one for example:

If you don't wanna use this, here are some tips:

  • Images on ImageViews are set with setImageDrawable(Drawable)

  • When your animation starts, set the new Image to your ImageView behind and slide the visible one away.

  • When the visible ImageViewhas slided away, set it's visibility to GONEand move it behind the second ImageView

Do this for every time a new image is loaded.

This should actually work.