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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| public class MainActivity extends AppCompatActivity {
private int width; private int height; private ImageView imageView = null; private ImageView loveImageView = null;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.left); setSupportActionBar(toolbar);
getWidthAndHeight(); imageView = (ImageView) findViewById(R.id.ball); loveImageView = (ImageView) findViewById(R.id.love); }
public void doAnimation(final View view) { PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0.8f, 1f, 0.8f, 1.0f); PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 0.6f, 0.8f, 1f, 0.8f, 1.0f); PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 0.6f, 0.8f, 1f, 0.8f, 1.0f); ObjectAnimator.ofPropertyValuesHolder(loveImageView, pvhX, pvhY, pvhZ).setDuration(1000).start(); }
public void doGtAnimation(final View view) { ObjectAnimator anim = ObjectAnimator.ofFloat(imageView, "yidong", 0, 1, 0).setDuration(3000); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float cVal = (Float) animation.getAnimatedValue(); imageView.setX(5 * cVal * 100); imageView.setY(5 * cVal * 3 * cVal * 3 * 100); } }); anim.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { System.err.println("yidong -- onAnimationStart"); }
@Override public void onAnimationEnd(Animator animation) { System.err.println("yidong -- onAnimationEnd"); }
@Override public void onAnimationCancel(Animator animation) { System.err.println("yidong -- onAnimationCancel"); }
@Override public void onAnimationRepeat(Animator animation) { System.err.println("yidong -- onAnimationRepeat"); } }); anim.setRepeatMode(ValueAnimator.RESTART); anim.setRepeatCount(2); anim.start();
}
public void doCircleAnimation(View view) { ObjectAnimator anim = ObjectAnimator.ofFloat(imageView, "yidong", 0, 2 * (float) Math.PI).setDuration(1000); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { System.err.println("yidong -- value = " + animation.getAnimatedValue()); float cVal = (Float) animation.getAnimatedValue(); imageView.setX((float) Math.sin(cVal) * 200 + width / 2); imageView.setY((float) Math.cos(cVal) * 200 + height / 2); } }); anim.setRepeatMode(ValueAnimator.REVERSE); anim.setRepeatCount(-1); anim.start(); }
public void doXmlAnimation(View view) { Animator animator = AnimatorInflater.loadAnimator(this, R.animator.one); animator.setTarget(loveImageView); animator.start(); }
private void getWidthAndHeight() { WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); width = dm.widthPixels; height = dm.heightPixels; System.err.println("yidong -- width = " + width); System.err.println("yidong -- height = " + height); } }
|