Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransitionDrawable completed

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

like image 380
Tony Avatar asked Jan 12 '12 19:01

Tony


People also ask

What is transition drawable?

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.


2 Answers

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.

like image 70
Tony Avatar answered Oct 01 '22 02:10

Tony


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.

like image 43
Chris Blunt Avatar answered Oct 01 '22 02:10

Chris Blunt