Skip to content

Instantly share code, notes, and snippets.

@jarylan
Created February 20, 2017 02:48
Show Gist options
  • Save jarylan/2bea6c68608da2b00558cc9b3ae7c220 to your computer and use it in GitHub Desktop.
Save jarylan/2bea6c68608da2b00558cc9b3ae7c220 to your computer and use it in GitHub Desktop.
mPath = new Path();
mPath.moveTo(POINT0[0], POINT0[1]);
mPath.lineTo(POINT1[0], POINT1[1]);
mPath.cubicTo(POINT1[0], POINT1[1], POINT2[0], POINT2[1],POINT3[0], POINT3[1]);//贝塞尔曲线
mPath.lineTo(POINT4[0], POINT4[1]);
mPath.cubicTo(POINT4[0], POINT4[1], POINT5[0], POINT5[1],POINT6[0], POINT6[1]);
mPathMeasure = new PathMeasure(mPath, true);//true 执行一次
mCurrentPosition = setPoint((float)POINT0[0],(float)POINT0[1]);
@Override
protected void onDraw(Canvas canvas) {
// 绘制对应目标
canvas.drawBitmap(bmp, mCurrentPosition[0], mCurrentPosition[1], mPaint);
}
// 开启路径动画
public void startPathAnim(long duration) {
if(mPathMeasure==null){
return;
}
// 0 - getLength()
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, mPathMeasure.getLength());
Log.i(TAG, "---------------measure length = " + mPathMeasure.getLength());
valueAnimator.setDuration(duration);
valueAnimator.setRepeatCount(valueAnimator.INFINITE);
// 减速插值器
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
// 获取当前点坐标封装到mCurrentPosition
mPathMeasure.getPosTan(value, mCurrentPosition, null);
postInvalidate();
}
});
valueAnimator.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment