属性动画ValueAnimator与ObjectAnimator


ValueAnimator的简单应用

///初始化,设置初始值和结束 //ValueAnimator valueAnimator=ValueAnimator.ofFloat(0.4f,8.7f,3,5); //valueAnimator.ofInt(2,1,3); ////动画执行时间,初始值到结束值的过渡时间 //valueAnimator.setDuration(1000); ////启动动画; //valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { //@Override //public void onAnimationUpdate(ValueAnimator animation) { ////监听执行过程。 //// System.out.println(animation.getAnimatedValue()); //} //}); //valueAnimator.start();

ObjectAnimator的简单使用

//ObjectAnimator moveIn = ObjectAnimator.ofFloat(textView, "translationX", -500f, 0f); //ObjectAnimator rotate = ObjectAnimator.ofFloat(textView, "rotation", 0f, 360f); //ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(textView, "alpha", 1f, 0f, 1f); //AnimatorSet animSet = new AnimatorSet(); //animSet.play(rotate).with(fadeInOut).after(moveIn); //animSet.setDuration(5000); ////动画监听,不需要重新所有方法 //animSet.addListener(new AnimatorListenerAdapter() { //@Override //public void onAnimationEnd(Animator animation) { //super.onAnimationEnd(animation); //} //}); //animSet.start();

Animator 利用xml实现动画

img = findViewById(R.id.animat); @SuppressLint("ResourceType") Animator animator = AnimatorInflater.loadAnimator(this, R.anim.anim_lay); animator.setTarget(img); animator.start(); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); Intent intent = new Intent(AnimtorActivity.this,MainActivity.class); startActivity(intent); finish(); } }); }


xml文件




【属性动画ValueAnimator与ObjectAnimator】



    推荐阅读