标签:
在nineoldandroids库中有三种方式实现控件的动画效果。
第一:
PROXY_PROPERTIES.put("alpha", PreHoneycombCompat.ALPHA);
PROXY_PROPERTIES.put("pivotX", PreHoneycombCompat.PIVOT_X);
PROXY_PROPERTIES.put("pivotY", PreHoneycombCompat.PIVOT_Y);
PROXY_PROPERTIES.put("translationX", PreHoneycombCompat.TRANSLATION_X);
PROXY_PROPERTIES.put("translationY", PreHoneycombCompat.TRANSLATION_Y);
PROXY_PROPERTIES.put("rotation", PreHoneycombCompat.ROTATION);
PROXY_PROPERTIES.put("rotationX", PreHoneycombCompat.ROTATION_X);
PROXY_PROPERTIES.put("rotationY", PreHoneycombCompat.ROTATION_Y);
PROXY_PROPERTIES.put("scaleX", PreHoneycombCompat.SCALE_X);
PROXY_PROPERTIES.put("scaleY", PreHoneycombCompat.SCALE_Y);
PROXY_PROPERTIES.put("scrollX", PreHoneycombCompat.SCROLL_X);
PROXY_PROPERTIES.put("scrollY", PreHoneycombCompat.SCROLL_Y);
PROXY_PROPERTIES.put("x", PreHoneycombCompat.X);
PROXY_PROPERTIES.put("y", PreHoneycombCompat.Y);
ObjectAnimator.ofFloat(target, "translationX", 0, 50, -50, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "translationY", 0, 50, -50, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "scaleX", 1, 2, 1).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "scaleY", 1, 2, 1).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "alpha", 1, 0, 1).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "rotationX", 0, 180, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "rotationY", 0, 180, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "rotation", 0, 180, 0).setDuration(duration).start();
//以下两个是自定义的,要在View加入setPhaseX getPhaseX,setPhaseY, getPhaseY, mPhaseY, mPhaseX定义;
ObjectAnimator.ofFloat(target, "phaseY", 0f, 1f).setDuration(durationMillisY).start();
ObjectAnimator.ofFloat(target, "phaseX", 0f, 1f).setDuration(durationMillisX).start();
AnimatorPath path = new AnimatorPath();
path.moveTo(0, 0);
path.lineTo(0, 300);
path.curveTo(100, 0, 300, 900, 400, 500);
ObjectAnimator.ofObject(target, "buttonLoc", new PathEvaluator(), path.getPoints().toArray()).setDuration(1000).start();
////
ObjectAnimator.ofFloat(target, "translationX", 0, 50, -50, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "translationY", 0, 50, -50, 0).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "scaleX", 1, 2, 1).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "scaleY", 1, 2, 1).setDuration(duration).start();
ObjectAnimator.ofFloat(target, "alpha", 1, 0, 1).setDuration(duration).start();
//=======
ObjectAnimator.ofFloat(target, "rotationX", 0, 180, 0).setDuration(duration).start(); // x轴旋转
ObjectAnimator.ofFloat(target, "rotationY", 0, 180, 0).setDuration(duration).start(); // y轴旋转
ObjectAnimator.ofFloat(target, "rotation", 0, 180, 0).setDuration(duration).start(); // z轴旋转
// 设置旋转中心点(0,0)
ViewHelper.setPivotX(target, 0);
ViewHelper.setPivotY(target, 0);
// 设置旋转中心点(width/2,height/2)
ViewHelper.setPivotX(target, target.getWidth() / 2f);
ViewHelper.setPivotY(target, target.getHeight() / 2f);
//设置旋转中心点(width,height)
ViewHelper.setPivotX(target, target.getWidth());
ViewHelper.setPivotY(target, target.getHeight());
//=======
第二:
animate(target).setDuration(2000).alpha(0);
animate(target).setDuration(2000).alpha(1);
animate(target).setDuration(2000)..x(xValue).y(yValue);
animate(target).setDuration(2000)..x(0).y(0);
animate(target).setDuration(2000).rotationYBy(720);
第三:
ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();
ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
bounceAnim.setDuration(duration);
bounceAnim.setInterpolator(new AccelerateInterpolator());
ValueAnimator squashAnim1 = ObjectAnimator.ofFloat(newBall, "x", newBall.getX(), newBall.getX() - 25f);
squashAnim1.setDuration(duration/4);
squashAnim1.setRepeatCount(1);
squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
squashAnim1.setInterpolator(new DecelerateInterpolator());
ValueAnimator squashAnim2 = ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(), newBall.getWidth() + 50);
squashAnim2.setDuration(duration/4);
squashAnim2.setRepeatCount(1);
squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
squashAnim2.setInterpolator(new DecelerateInterpolator());
ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY, endY + 25f);
stretchAnim1.setDuration(duration/4);
stretchAnim1.setRepeatCount(1);
stretchAnim1.setInterpolator(new DecelerateInterpolator());
stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
ValueAnimator stretchAnim2 = ObjectAnimator.ofFloat(newBall, "height", newBall.getHeight(), newBall.getHeight() - 25);
stretchAnim2.setDuration(duration/4);
stretchAnim2.setRepeatCount(1);
stretchAnim2.setInterpolator(new DecelerateInterpolator());
stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY, startY);
bounceBackAnim.setDuration(duration);
bounceBackAnim.setInterpolator(new DecelerateInterpolator());
// Sequence the down/squash&stretch/up animations
AnimatorSet bouncer = new AnimatorSet();
bouncer.play(bounceAnim).before(squashAnim1);
bouncer.play(squashAnim1).with(squashAnim2);
bouncer.play(squashAnim1).with(stretchAnim1);
bouncer.play(squashAnim1).with(stretchAnim2);
bouncer.play(bounceBackAnim).after(stretchAnim2);
// Fading animation - remove the ball when the animation is done
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
fadeAnim.setDuration(250);
fadeAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
balls.remove(((ObjectAnimator)animation).getTarget());
}
});
// Sequence the two animations to play one after the other
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(bouncer).before(fadeAnim);
// Start the animation
animatorSet.start();
标签:
原文地址:http://blog.csdn.net/a_little_a_day/article/details/44459179