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 54 55 56 57 58 59 60 61 62 63 64 65
| package com.qefee.pj.testanim;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
Button alphaButton = (Button) findViewById(R.id.alphaButton); Button scaleButton = (Button) findViewById(R.id.scaleButton); Button transButton = (Button) findViewById(R.id.transButton); Button rotateButton = (Button) findViewById(R.id.rotateButton);
doAnim(alphaButton, R.anim.anim_alpha, R.anim.anim_alpha_inverse); doAnim(scaleButton, R.anim.anim_scale, R.anim.anim_scale_inverse); doAnim(transButton, R.anim.anim_trans, R.anim.anim_trans_inverse); doAnim(rotateButton, R.anim.anim_rotate, R.anim.anim_rotate_inverse); }
private void doAnim(Button scaleButton, final int anim, final int animInverse) { scaleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, anim);
animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { Toast.makeText(MainActivity.this, "动画开始了", Toast.LENGTH_SHORT).show(); }
@Override public void onAnimationEnd(Animation animation) { Toast.makeText(MainActivity.this, "动画结束了", Toast.LENGTH_SHORT).show();
Animation animation1 = AnimationUtils.loadAnimation(MainActivity.this, animInverse); imageView.startAnimation(animation1); }
@Override public void onAnimationRepeat(Animation animation) { Toast.makeText(MainActivity.this, "动画重播了", Toast.LENGTH_SHORT).show(); } }); imageView.startAnimation(animation); } }); } }
|