- android animation through button
- import android.app.Activity;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Matrix;
- import android.graphics.drawable.BitmapDrawable;
- import android.os.Bundle;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.AccelerateInterpolator;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- import android.widget.ImageView;
- public class dash1 extends Activity {
- ImageView img, img1;
- Animation an, an1, an2, an3, an4, an5;
- Button bt, bt2, bt3, bt4, bt5, bt6;
- /** Called when the activity is first created. */
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- img = (ImageView) findViewById(R.id.ImageView01);
- final Bitmap bmp = BitmapFactory.decodeResource(getResources(),
- R.drawable.minute);
- final int w = bmp.getWidth();
- final int h = bmp.getHeight();
- final Matrix mat = new Matrix();
- mat.postRotate(245);
- Bitmap rtd = Bitmap.createBitmap(bmp, 0, 0, w, h, mat, true);
- BitmapDrawable bmd = new BitmapDrawable(rtd);
- img.setImageDrawable(bmd);
- an = AnimationUtils.loadAnimation(this, R.anim.anim);
- an1 = AnimationUtils.loadAnimation(this, R.anim.anim1);
- an2 = AnimationUtils.loadAnimation(this, R.anim.anim2);
- an3 = AnimationUtils.loadAnimation(this, R.anim.anim3);
- an4 = AnimationUtils.loadAnimation(this, R.anim.anim4);
- an5 = AnimationUtils.loadAnimation(this, R.anim.anim5);
- bt = (Button) findViewById(R.id.Button01);
- bt2 = (Button) findViewById(R.id.Button02);
- bt3 = (Button) findViewById(R.id.Button03);
- bt4 = (Button) findViewById(R.id.Button04);
- bt5 = (Button) findViewById(R.id.Button05);
- bt6 = (Button) findViewById(R.id.Button06);
- bt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- an.setFillAfter(true);
- img.startAnimation(an);
- }
- });
- bt2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- img.startAnimation(an1);
- }
- });
- bt3.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- an2.setFillAfter(true);
- img.startAnimation(an2);
- }
- });
- bt4.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- an3.setFillAfter(true);
- img.startAnimation(an3);
- }
- });
- bt5.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- an2.setFillAfter(true);
- img.startAnimation(an4);
- }
- });
- bt6.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- an5.setFillAfter(true);
- img.startAnimation(an5);
- }
- });
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android"
- android:shareInterpolator="false">
- <rotate android:toYScale="0.0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:duration="3599"
- android:fromDegrees="0"
- android:toDegrees="205">
- </rotate>
- </set>