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 Activity Transitions: Advanced Topics Using XML to Customize Activity Transitions

Boban Talevski
Boban Talevski
24,793 Points

Help with the exercise mentioned near the end of the video about activity transitions in XML

Can we get a bit more help with the exercise mentioned near the end of the video (at about 4:30)?

Namely, we did set up the basics of Activity Transitions in the styles-v21 file by adding this item in the themes

        <item name="android:windowEnterTransition">@android:transition/slide_right</item>

So this means that all activities in the app will slide from the right, which is ok (5.0 or greater). But how do we add more specific details about the activity transitions in XML?

And what if we want to have different transitions for different activities. Do we create specific themes per activity with respective transitions and apply that theme to each activity in the manifest?

This seems to be an important topic as I don't see myself using activity transitions in code anytime soon (assuming we want our apps to be backwards compatible at least to 4.4 or so), so we should use the XML option more often I guess. Thus, we could use some basic pointers/examples or maybe even an additional video added in this course at the end of this section giving some basic examples about activity transitions in XML so we at least know where to start when delving deeper in the subject.

Hello, Ben Jakuben Sir, please take a look at the question it seems important to me.

1 Answer

Ryan Jones
Ryan Jones
1,378 Points

In themes in v21/styles.xml, I changed from slide_right to slide_bottom and set windowSharedElementsUseOverlay to false. This matches what Ben had done in Java code.

<item name="android:windowEnterTransition">@transition/slide_bottom</item>
<item name="android:windowSharedElementsUseOverlay">false</item>

I added my own slide_bottom transition under the res/transition folder in v21/slide_bottom.xml. It specifically excludes the status bar from the transition animation, also to match what Ben had done in Java code:

<?xml version="1.0" encoding="utf-8"?>
<slide
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:slideEdge="bottom">
    <targets>
        <target android:excludeId="@android:id/statusBarBackground" />
    </targets>
</slide>

Thank you! This helped me understand how the Java transition gets translated into XML and vice-versa.