Tag Archives: Animations

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 –

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 –

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

MainActivity.java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

packagecom.example.anim;

//copyright androidarena.co.in

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

publicclassMainActivityextendsActivity{

Button top_botom,scnd,thrd,frth,showbtn;

@Override

protectedvoidonCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

top_botom=(Button)findViewById(R.id.btn1);

scnd=(Button)findViewById(R.id.btn2);

thrd=(Button)findViewById(R.id.btn3);

frth=(Button)findViewById(R.id.btn4);

showbtn=(Button)findViewById(R.id.click);

showbtn.setOnClickListener(newOnClickListener(){

@Override

publicvoidonClick(Viewv){

// top to bottom animation............................

TranslateAnimation trans1=newTranslateAnimation(0,0,-100,0);

trans1.setDuration(1000);

top_botom.setAnimation(trans1);

//botom to top animation...........................

TranslateAnimation trans2=newTranslateAnimation(0,0,100,0);

trans2.setDuration(1000);

scnd.setAnimation(trans2);

//left to right animation.............................

TranslateAnimation trans3=newTranslateAnimation(100,0,0,0);

trans3.setDuration(1000);

thrd.setAnimation(trans3);

// right to left animation..............................

TranslateAnimation trans4=newTranslateAnimation(-100,0,0,0);

trans4.setDuration(1000);

frth.setAnimation(trans4);

}

});

}

}

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

Output –

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