Question

I just looked at the twitter app and it seems to have a nice sliding transition while moving from one screen to the next. I'm trying to get the same behavior in my app.

Currently I move between screens with:

startActivityForResult(new Intent(getApplicationContext(), MyActivity.class), 1);

But this way there is no transition between the screen. The MyActivity just pops up on the screen.

Was it helpful?

Solution

Animations with drawables:

This tutorial might help you to understand how it works. First, you should create a folder named anim in /res/ folder. Then, create and put into it the drawables which will be uses to make a transition animation as follows:

anim_left_to_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate 
        android:fromXDelta="-100%"
        android:toXDelta="0%"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>  

anim_right_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate 
        android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>  

Then, use overridePendingTransition() method to call the drawables and apply them to the startActivity() (or startActivityForResult()) method:

startActivityForResult(new Intent(getApplicationContext(), MyActivity.class), 1);
overridePendingTransition(anim_left_to_right, anim_right_to_left);

Custom animations relative to lifecycle:

You can also make custom animations, "regardless startActivity method", but in using the lifecycle of activities: I mean like Vine when you call the enter animation into onCreate() and the out animation into onPause(). This is a great demo about this kind of feature.

OTHER TIPS

Call overridePendingTransition(entry_anim, exit_anim) after calling the startActivity().

You can specify the entry and exit animations through xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top