I am running an animation in my Android app using the following code:
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relativeLayout1);
layout.setBackgroundResource(R.drawable.translate);
final TransitionDrawable transition = (TransitionDrawable) layout.getBackground();
transition.startTransition(9000);
The animation runs for 9 seconds, and then it needs to be reversed.
At the moment I am using a countdown timer (already one running in the app), to check if 9 seconds has gone by and manually reverse the transition....
Is there a better way to do this?
Thanks
android.graphics.drawable.TransitionDrawable. An extension of LayerDrawables that is intended to cross-fade between the first and second layer. To start the transition, call startTransition(int) . To display just the first layer, call resetTransition() . It can be defined in an XML file with the <transition> element.
To answer my own question, no there is no onCompletionListener. Instead you do have to manually count the seconds and then reverse the transision.
I also asked this question during an Android Developer Hangout with Google, and it could not be answered in any other way.
I've recently come up against this problem and needed to transition between several images in a loop. I've posted an answer here with a custom class based on TransitionDrawable. It would be fairly simple to build callbacks into that class.
Hopefully this will help anyone else struggling with TransitionDrawables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With