Search Wikipedia

Search results

Oct 17, 2013

Tween animation in Android

Using Tween animation


After frambyframe animation lets focus on tween animation, it is much simpler to program essentially we give start and end values to android and it gonna interpolate the values between them itself.
First of all i make a blank project called Tween.
Change the layout to relative but mine is relative layout by default.
Now i drag a button in the layout.

Dragging button in my layout


Now i am gonna create a new XML called animation.xml similar in framebyframe animation.I write this below codes in this XML file:


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator">// this is use for making slow starting of animation in start and speed up the speed of animation later
    <scale
        android:fromXScale="0.5"
        android:toXScale="2.0"
        android:fromYScale="0.5"
        android:toYScale="2.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"
        />
    <rotate 
        android:fromDegrees="0"
        android:toDegrees="180"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000"
        android:startOffset="1000"
        />
    </set>

Codes for Tween animation
Then i goto main java file where i need to initliaze the animation to the button.

For this i write the following code under the Oncreate function.

final Button b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {

public void onClick(View arg0) {
// TODO Auto-generated method stub
Animation anime = AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
b1.startAnimation(anime);

}
});



For animation running in real device is good because AVD is slow and we cant test our animation better in AVD.

Anyway my project looks like this :








No comments:

Post a Comment

Did this post help you? Do you have any questions? Drop your thoughts here...

}