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.
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.
Call overridePendingTransition(entry_anim, exit_anim)
after calling the startActivity().
You can specify the entry and exit animations through xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With