This Animation Demo.....
Download This Code Click Here......
The view animation framework supports both tween and frame by frame animations, which can both be declared in XML. The following sections describe how to use both methods.
Download This Code Click Here......
The view animation framework supports both tween and frame by frame animations, which can both be declared in XML. The following sections describe how to use both methods.
Tween animation
An animation defined in XML that performs transitions such as rotating, fading, moving, and stretching on a graphic.
- file location:
res/anim/filename.xml
The filename will be used as the resource ID.- compiled resource datatype:
- Resource pointer to an
Animation
. - resource reference:
- In Java:
R.anim.filename
In XML:@[package:]anim/filename
- syntax:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@[package:]anim/interpolator_resource" android:shareInterpolator=["true" | "false"] > <alpha android:fromAlpha="float" android:toAlpha="float" /> <scale android:fromXScale="float" android:toXScale="float" android:fromYScale="float" android:toYScale="float" android:pivotX="float" android:pivotY="float" /> <translate android:fromXDelta="float" android:toXDelta="float" android:fromYDelta="float" android:toYDelta="float" /> <rotate android:fromDegrees="float" android:toDegrees="float" android:pivotX="float" android:pivotY="float" /> <set> ... </set> </set>
The file must have a single root element: either an<alpha>
,<scale>
,<translate>
,<rotate>
, or<set>
element that holds a group (or groups) of other animation elements (even nested<set>
elements).- elements:
- example:
XML file saved at res/anim/
property.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/accelerate_interpolator" android:startOffset="700"> <scale android:fromXScale="5.6" android:toXScale="2" android:fromYScale="5.0" android:toYScale="0.0" android:pivotX="25%" android:pivotY="50%" android:duration="500" /> <rotate android:fromDegrees="0" android:toDegrees="-90" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="700" /> </set> </set>
This application code will apply the animation to anImageView
and start the animation:import android.os.Bundle; import android.animation.AnimatorInflater; import android.animation.AnimatorSet; import android.app.Activity; import android.view.Menu; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.TextView; //O@K Tech.. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animator); ImageView img = (ImageView)findViewById(R.id.imageView1); Animation amnt = AnimationUtils.loadAnimation(this,R.anim.property); img.startAnimation(amnt); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
Comments
Post a Comment