Open an activity with animation in Android

One of the funny part of mobile development for me is animations. When developing a mobile application, time to time we are working on animations for better user interaction and experience. Android has good animation classes like android.view.animation and Animation. And a lot of apps are using this classes very well for views and widgets.

Normally, when we are developing an app we don't do any animations for activity transitions. Because, Android do this for us. And our apps use default system animations for activity transitions. When i am working on animations, i have created an AnimatedActivity class for activity transitions. With this class you can open your activities from left, right, top or bottom of screen. And it is closed where it is coming from.

How can you use it?

First, add AnimatedActivity base class to your project.


After that, add animations to your res/anim directory.


That's all.

And here is the usage,
First, extends your activities from AnimatedActivity
public class NewActivity extends AnimatedActivity
After that, open your NewActivity from MainActivity with "startAnimatedActivity" method like standart "startActivity" method
Intent intent = new Intent(MainActivity.this, NewActivity.class);
startAnimatedActivity(intent, AnimatedActivity.SLIDE_FROM_LEFT);

"startAnimatedActivity" is the method that is in the AnimatedActivity class. And usage is the same as default "startActivity" method of Android. Of course, AnimatedActivity class has a "startAnimatedActivityForResult" method like as default "startActivityForResult" method.

You don't need to care about close animation. Because, AnimatedActivity class has an overloaded "finish" method to close activity with transition when user click device back button or close button on your ui which is called finish method.

You can find source code and sample usage on

0 comments:

Post a Comment