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

Leonardo Fettucciari
Leonardo Fettucciari
633 Points

TransitionManager.setTransition(), why used twice here?

Hi, I don't understand why we added these two lines of code in this same place, wouldn't they override themselves?

What's really happening behind the scenes in this couple of lines?

private void setupTransitions() {
// Expanded scene
// Collapsed scene
        mTransitionManager.setTransition(mExpandedScene, mCollapsedScene, collapseTransitionSet);
        mTransitionManager.setTransition(mCollapsedScene, mExpandedScene, expandTransitionSet);

1 Answer

I think of the transitionManager as a sort of librarian, just keeping track of the different "books". When you need a transition, you go to the librarian and ask for the one you need, and they give it to you. The transition actually happens in this code:

    public void onTrackPanelClicked(View view) {
        if (mCurrentScene == mExpandedScene) {
            mCurrentScene = mCollapsedScene;
        } else {
            mCurrentScene = mExpandedScene;

You can see that this method first figures out "where you are" and then asks mTransitionManager to get us to "the other place".

[MOD: edited code block and marked thread resolved]