/**
* http://blog.csdn.net/lmj623565791/article/details/38067475
*/
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.image_view);
}
public void trans(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "y", 0, 1300);
animator.setDuration(3000);
animator.setInterpolator(new AccelerateInterpolator());//加速的插值器
animator.start();
//监听事件
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Toast.makeText(MainActivity.this,"结束,跳转页面",Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
public void rotrate(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
animator.setDuration(3000);
animator.start();
}
public void alpha(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 0, 1);
animator.setDuration(3000);
animator.start();
}
public void scale(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 0, 2);
animator.setDuration(3000);
animator.start();
}
@SuppressLint("ObjectAnimatorBinding")
public void zuhe_01(View view) {
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageView, "abc", 0, 1);
objectAnimator.setDuration(4000);
objectAnimator.start();
//动画的属性值不停更新的方法
objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//属性的值
float animatedValue = (float) valueAnimator.getAnimatedValue();
imageView.setScaleX(animatedValue);
imageView.setScaleY(animatedValue);
imageView.setAlpha(animatedValue);
}
});
}
public void zuhe_02(View view) {
ObjectAnimator y = ObjectAnimator.ofFloat(imageView, "y", 0, 10, 200, 250, 500, 1000, 1100, 1300);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 0.5f, 2);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 0.5f, 2);
ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 0.5f, 1.0f);
ObjectAnimator rotationX = ObjectAnimator.ofFloat(imageView, "rotationX", 0, 360);
ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
AnimatorSet animatorSet = new AnimatorSet();
//设置
/*animatorSet.play(y).before(scaleX);
animatorSet.play(scaleX).with(scaleY);
animatorSet.play(alpha).with(scaleY);
animatorSet.play(rotationX).with(alpha).with(rotationY);*/
animatorSet.play(y).with(scaleX).with(scaleY).with(alpha);
animatorSet.setDuration(5000);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
}
* http://blog.csdn.net/lmj623565791/article/details/38067475
*/
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.image_view);
}
public void trans(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "y", 0, 1300);
animator.setDuration(3000);
animator.setInterpolator(new AccelerateInterpolator());//加速的插值器
animator.start();
//监听事件
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Toast.makeText(MainActivity.this,"结束,跳转页面",Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
public void rotrate(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
animator.setDuration(3000);
animator.start();
}
public void alpha(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 0, 1);
animator.setDuration(3000);
animator.start();
}
public void scale(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 0, 2);
animator.setDuration(3000);
animator.start();
}
@SuppressLint("ObjectAnimatorBinding")
public void zuhe_01(View view) {
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageView, "abc", 0, 1);
objectAnimator.setDuration(4000);
objectAnimator.start();
//动画的属性值不停更新的方法
objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//属性的值
float animatedValue = (float) valueAnimator.getAnimatedValue();
imageView.setScaleX(animatedValue);
imageView.setScaleY(animatedValue);
imageView.setAlpha(animatedValue);
}
});
}
public void zuhe_02(View view) {
ObjectAnimator y = ObjectAnimator.ofFloat(imageView, "y", 0, 10, 200, 250, 500, 1000, 1100, 1300);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 0.5f, 2);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 0.5f, 2);
ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 0.5f, 1.0f);
ObjectAnimator rotationX = ObjectAnimator.ofFloat(imageView, "rotationX", 0, 360);
ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
AnimatorSet animatorSet = new AnimatorSet();
//设置
/*animatorSet.play(y).before(scaleX);
animatorSet.play(scaleX).with(scaleY);
animatorSet.play(alpha).with(scaleY);
animatorSet.play(rotationX).with(alpha).with(rotationY);*/
animatorSet.play(y).with(scaleX).with(scaleY).with(alpha);
animatorSet.setDuration(5000);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
}