Android Adding Animation Tutorial

Animation is a process of making motion and changes on the user interfaces. Therefore, Animation is important when come to create smooth screen changes to the end user so that user wont see any delay in short it improving the user experience. For android, there have many methods to implement animation such as you can implement via xml or java source code. You can control how the animation perform in the application. In this tutorial, I will teach you how to use android adding animation in your own app so you can provide better user experience to user.

Sample Screen Android Adding Animation

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “AnimationExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Create 3 activity

Right click your package name and create 3 new activity which name “SharedElementActivity”, “TransitionActivity” and “ViewAnimationActivity”.

Edit activity_shared.xml layout

Go to the resource folder and edit this xml layout for SharedElementActivity. It will be add an ImageView and it must have transitionName so that can perform shared element animation later.

Edit activity_view_animation.xml layout

Modify the activity_view_animation layout to the following source code. Add imageview so later can be perform some animation in this imageview.

Edit activity_main.xml layout

Go to activity_main.xml and add 3 buttons on the layout, after that add the imageview so you can see shared element effect later.

Create animation folder

Right click res > new > Android resource directory > pick resource type “anim” and click OK buttons. The new resource folder will be created.

Add new slide in animations file

Create a new xml file “slidein.xml” in the anim folder. And add the following source code.

Add new slide out animations file

Create a new xml file “slideout.xml” in the anim folder. And add the following source code.

Add animation file for image

This xml file name “imageanimation.xml” and It will perform enlarge image animation.

Edit TransitionActivity.java class

Go to transitionAcitivty.java and add overridependingtransition in the onCreate and onPause method. This will use slidein and slideout animation.

Edit ViewAnimation.java class

This class perform the animation from the “imageanimation.xml”.

Edit MainActivity.class java

Modify to the source code below. It will link to another activity for each button with different animation effect.

Run Your Project

In conclusion, you now finish to implements some simple animation in the android application. Run your project in your emulator now.

(Android Adding Animation)

Source Code

(Visited 302 times, 1 visits today)
Advertisements

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *