Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 3.99 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. android animation through button
  2. import android.app.Activity;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.graphics.Matrix;
  6. import android.graphics.drawable.BitmapDrawable;
  7. import android.os.Bundle;
  8. import android.view.MotionEvent;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.view.animation.AccelerateInterpolator;
  12. import android.view.animation.Animation;
  13. import android.view.animation.AnimationUtils;
  14. import android.widget.Button;
  15. import android.widget.ImageView;
  16.  
  17. public class dash1 extends Activity {
  18.     ImageView img, img1;
  19.     Animation an, an1, an2, an3, an4, an5;
  20.     Button bt, bt2, bt3, bt4, bt5, bt6;
  21.  
  22.     /** Called when the activity is first created. */
  23.     public void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.main);
  26.         img = (ImageView) findViewById(R.id.ImageView01);
  27.         final Bitmap bmp = BitmapFactory.decodeResource(getResources(),
  28.                 R.drawable.minute);
  29.         final int w = bmp.getWidth();
  30.         final int h = bmp.getHeight();
  31.         final Matrix mat = new Matrix();
  32.         mat.postRotate(245);
  33.         Bitmap rtd = Bitmap.createBitmap(bmp, 0, 0, w, h, mat, true);
  34.         BitmapDrawable bmd = new BitmapDrawable(rtd);
  35.         img.setImageDrawable(bmd);
  36.         an = AnimationUtils.loadAnimation(this, R.anim.anim);
  37.         an1 = AnimationUtils.loadAnimation(this, R.anim.anim1);
  38.         an2 = AnimationUtils.loadAnimation(this, R.anim.anim2);
  39.         an3 = AnimationUtils.loadAnimation(this, R.anim.anim3);
  40.         an4 = AnimationUtils.loadAnimation(this, R.anim.anim4);
  41.         an5 = AnimationUtils.loadAnimation(this, R.anim.anim5);
  42.         bt = (Button) findViewById(R.id.Button01);
  43.         bt2 = (Button) findViewById(R.id.Button02);
  44.         bt3 = (Button) findViewById(R.id.Button03);
  45.         bt4 = (Button) findViewById(R.id.Button04);
  46.         bt5 = (Button) findViewById(R.id.Button05);
  47.         bt6 = (Button) findViewById(R.id.Button06);
  48.         bt.setOnClickListener(new View.OnClickListener() {
  49.  
  50.             @Override
  51.             public void onClick(View v) {
  52.                 // TODO Auto-generated method stub
  53.                 an.setFillAfter(true);
  54.                 img.startAnimation(an);
  55.  
  56.             }
  57.         });
  58.  
  59.         bt2.setOnClickListener(new View.OnClickListener() {
  60.  
  61.             @Override
  62.             public void onClick(View v) {
  63.                 // TODO Auto-generated method stub
  64.                 img.startAnimation(an1);
  65.             }
  66.         });
  67.         bt3.setOnClickListener(new View.OnClickListener() {
  68.  
  69.             @Override
  70.             public void onClick(View v) {
  71.                 // TODO Auto-generated method stub
  72.                 an2.setFillAfter(true);
  73.                 img.startAnimation(an2);
  74.  
  75.             }
  76.         });
  77.         bt4.setOnClickListener(new View.OnClickListener() {
  78.  
  79.             @Override
  80.             public void onClick(View v) {
  81.                 // TODO Auto-generated method stub
  82.                 an3.setFillAfter(true);
  83.                 img.startAnimation(an3);
  84.             }
  85.         });
  86.         bt5.setOnClickListener(new View.OnClickListener() {
  87.  
  88.             @Override
  89.             public void onClick(View v) {
  90.                 // TODO Auto-generated method stub
  91.  
  92.                 an2.setFillAfter(true);
  93.                 img.startAnimation(an4);
  94.             }
  95.         });
  96.         bt6.setOnClickListener(new View.OnClickListener() {
  97.  
  98.             @Override
  99.             public void onClick(View v) {
  100.                 // TODO Auto-generated method stub
  101.                 an5.setFillAfter(true);
  102.                 img.startAnimation(an5);
  103.             }
  104.         });
  105.     }
  106. }
  107.        
  108. <?xml version="1.0" encoding="utf-8"?>
  109. <set xmlns:android="http://schemas.android.com/apk/res/android"
  110.     android:shareInterpolator="false">
  111.     <rotate android:toYScale="0.0"
  112.         android:pivotX="50%"
  113.         android:pivotY="50%"
  114.         android:duration="3599"
  115.         android:fromDegrees="0"
  116.         android:toDegrees="205">
  117.      </rotate>
  118. </set>