public void paowuxian() { AnimatorSet animSet; ObjectAnimator rotateAnim = ObjectAnimator.ofFloat(imageview, "rotation", 0, 360); rotateAnim.setRepeatCount(-1); ValueAnimator valueAnimator = new ValueAnimator(); valueAnimator.setDuration(5000); valueAnimator.setObjectValues(new PointF(0, 0)); valueAnimator.setInterpolator(new LinearInterpolator()); valueAnimator.setEvaluator(new TypeEvaluator<PointF>() { @Override public PointF evaluate(float fraction, PointF startValue, PointF endValue) { PointF point = new PointF(); //抛物线 x方向200px/s ,则y方向0.5 * 10 * t //point.x = 200 * fraction * 3; //point.y = 0.5f * 200 * (fraction * 3) * (fraction * 3); //正弦曲线 point.x = 200 * fraction * 6 + 50; point.y = (float) (Math.sin(point.x * Math.PI / 180) * 100) + endValue.y / 2 + 200; return point; } }); //valueAnimator.start(); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { PointF point = (PointF) animation.getAnimatedValue(); imageview.setX(point.x); imageview.setY(point.y); } }); TimeInterpolator interpolatorType = new LinearInterpolator(); animSet = new AnimatorSet(); animSet.play(valueAnimator).with(rotateAnim); animSet.setDuration(5000); animSet.setInterpolator(interpolatorType); animSet.start(); }
Android属性动画
最新推荐文章于 2018-07-09 17:17:35 发布