Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Animations and Transitions The Transitions Framework Transitioning Back and Forth

How to create transitionset

Ordering_Sequentional constant not found.. Fade class also not found, how Can I create transitionSet

MainActivity.java
public class MainActivity extends Activity {

    protected TransitionManager mTransitionManager;
    protected Scene mScene1;
    protected Scene mScene2;
    protected Scene mCurrentScene;
    protected TransitionSet mForwardSet;
    protected TransitionSet mBackwardSet;

    // Some code omitted for brevity

    public void onButtonClicked(View view) {
        if (mCurrentScene == mScene2) {
            mCurrentScene = mScene1;
        }
        else {
            mCurrentScene = mScene2;
        }

      mTransitionManager.transitionTo(mCurrentScene);

    }

    protected void setupTransitions() {
        // These methods are setting up scenes and transitions sets like in the video


      mTransitionManager = new TransitionManager();

      TransitionSet forwordSet = new TransitionSet();
      TransitionSet backwordSet = new TransitionSet();
      forwordSet.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
      backwordSet.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);

      mTransitionManager.setTransition(mScene1, mScene2, forwordSet);
        mTransitionManager.setTransition(mScene2, mScene1, backwordSet);
      mScene2.enter();
        initScenes();
        initSets(); 

        // Start here!

    }
}

1 Answer

Seth Kroger
Seth Kroger
56,407 Points
    protected void setupTransitions() {
        // These methods are setting up scenes and transitions sets like in the video
        initScenes();  // <--- restore these two calls. you inadvertently removed them
        initSets(); 

        // Start here!
        mTransitionManager = new TransitionManager();

        // No need to set up the TransitionSets since the init methods take care of those.
        // Just set the two transitions asked for in the question.
        mTransitionManager.setTransition(mScene1, mScene2, mForwardSet);
        mTransitionManager.setTransition(mScene2, mScene1, mBackwardSet);        
    }