How to work on Android Animation Part 1 – TranslateAnimation Class

Posted on .
feature_output

Howdy developers , what’s going on ? Today I am going to show you how to make or call a Animation class so that you can achieve a very good animations in your application.So here I am going to describe very first and easy android animation tutorial so that your application will look cool and you will earn some penny .Lets dig inside –

Download Code

Basically what is TranslateAnimation class is that you need to invoke this class and you have to pass four parameters inside

 public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

As you can see there are four parameters inside i.e.

fromXDelta – This parameter is used , from where do you want to start Animation in X co-oridnate and you need to provide absolute value in percentage (1.0 means 100%).

toXDelta – This is used ,destination of view in X Co-oridnate.

fromYDelta – From where you want to start the animation in Y co-ordinate.

toXDelta – end of the animation in Y axis.

Lets start with first step i.e designing part  in XML , because my view is very simple you need to take your own View here I am going to use Buttons so that onClick event they perform different tasks like –

TOP TO BOTTOM

LEFT TO RIGHT

RIGHT TO LEFT

BOTTOM TO TOP

So in order to achieve this particular task you need to take view or buttons like i do –

activity_main.xml

you will see the following view in graphical layout –

animaion_part1

So , After making XMl part we need to call animation through Java class i.e TranslateAnimation class and we need to make its object.After making objects and you need to set Duration by calling object_name.setDuration(int time);

Now MainActivity.java

Now its time to Run the project :p Happy Coding …..

Output –

feature_output

Feel free to ask anything and any topic you want to cover . Ask in comment section 🙂