|
| 1 | +package com.clock.study.activity; |
| 2 | + |
| 3 | +import android.animation.Animator; |
| 4 | +import android.animation.AnimatorInflater; |
| 5 | +import android.animation.AnimatorSet; |
| 6 | +import android.animation.ObjectAnimator; |
| 7 | +import android.animation.ValueAnimator; |
| 8 | +import android.support.v7.app.AppCompatActivity; |
| 9 | +import android.os.Bundle; |
| 10 | +import android.util.Log; |
| 11 | +import android.view.View; |
| 12 | +import android.view.animation.AnimationSet; |
| 13 | + |
| 14 | +import com.clock.study.R; |
| 15 | + |
| 16 | +/** |
| 17 | + * About Android Animator |
| 18 | + * |
| 19 | + * @author Clock |
| 20 | + * @since 2016-07-21 |
| 21 | + */ |
| 22 | +public class AnimatorActivity extends AppCompatActivity implements View.OnClickListener { |
| 23 | + |
| 24 | + private static final String TAG = AnimatorActivity.class.getSimpleName(); |
| 25 | + |
| 26 | + @Override |
| 27 | + protected void onCreate(Bundle savedInstanceState) { |
| 28 | + super.onCreate(savedInstanceState); |
| 29 | + setContentView(R.layout.activity_animator); |
| 30 | + |
| 31 | + findViewById(R.id.btn_value_anim).setOnClickListener(this); |
| 32 | + findViewById(R.id.btn_object_anim_alpha).setOnClickListener(this); |
| 33 | + findViewById(R.id.btn_object_anim_rotation).setOnClickListener(this); |
| 34 | + findViewById(R.id.btn_object_anim_set).setOnClickListener(this); |
| 35 | + findViewById(R.id.btn_object_anim_xml).setOnClickListener(this); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void onClick(View v) { |
| 41 | + int viewId = v.getId(); |
| 42 | + if (viewId == R.id.btn_value_anim) { |
| 43 | + ValueAnimator valueAnimator = ValueAnimator.ofInt(1, 100); |
| 44 | + valueAnimator.setDuration(3000); |
| 45 | + valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 46 | + @Override |
| 47 | + public void onAnimationUpdate(ValueAnimator animation) { |
| 48 | + int currentValue = (int) animation.getAnimatedValue(); |
| 49 | + Log.i(TAG, "currentValue: " + currentValue); |
| 50 | + } |
| 51 | + }); |
| 52 | + valueAnimator.start(); |
| 53 | + } else if (viewId == R.id.btn_object_anim_alpha) { |
| 54 | + ObjectAnimator alphaObjectAnimator = ObjectAnimator.ofFloat(v, "alpha", 1f, 0f, 1f); |
| 55 | + alphaObjectAnimator.setDuration(3000); |
| 56 | + alphaObjectAnimator.start(); |
| 57 | + } else if (viewId == R.id.btn_object_anim_rotation) { |
| 58 | + ObjectAnimator rotationObjectAnimator = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f); |
| 59 | + rotationObjectAnimator.setDuration(3000); |
| 60 | + rotationObjectAnimator.start(); |
| 61 | + } else if (viewId == R.id.btn_object_anim_set) { |
| 62 | + AnimatorSet animatorSet = new AnimatorSet(); |
| 63 | + ObjectAnimator alphaObjectAnimator = ObjectAnimator.ofFloat(v, "alpha", 1f, 0f, 1f); |
| 64 | + ObjectAnimator rotationObjectAnimator = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f); |
| 65 | + animatorSet.play(alphaObjectAnimator).with(rotationObjectAnimator); |
| 66 | + //animatorSet.play(alphaObjectAnimator).after(rotationObjectAnimator); |
| 67 | + //animatorSet.playTogether(alphaObjectAnimator, rotationObjectAnimator); |
| 68 | + animatorSet.setDuration(3000); |
| 69 | + animatorSet.start(); |
| 70 | + } else if (viewId == R.id.btn_object_anim_xml) { |
| 71 | + AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.simple_animator); |
| 72 | + animatorSet.setTarget(v); |
| 73 | + animatorSet.start(); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments