Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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:

    @OnClick(R.id.track_panel)
    public void onTrackPanelClicked(View view) {
        if (mCurrentScene == mExpandedScene) {
            mCurrentScene = mCollapsedScene;
        } else {
            mCurrentScene = mExpandedScene;
        }
        mTransitionManager.transitionTo(mCurrentScene);
    }

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]