可以将动画制作器附加到路径吗?还有其他方法可以在画布上绘制动画线吗?我在发布之前搜索了此内容,但与此无关。在这里和这里的其他两个帖子中,有一些解决方案,不适合我。
我将代码发布在onDraw方法中,以指定确切的内容。
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(Color.BLACK);
Path path = new Path();
path.moveTo(10, 50); // THIS TRANSFORMATIONS TO BE ANIMATED!!!!!!!!
path.lineTo(40, 50);
path.moveTo(40, 50);
path.lineTo(50, 40);
// and so on...
canvas.drawPath(path, paint);
有任何想法吗????
您可以按时间变换画布,即:
class MyView extends View {
int framesPerSecond = 60;
long animationDuration = 10000; // 10 seconds
Matrix matrix = new Matrix(); // transformation matrix
Path path = new Path(); // your path
Paint paint = new Paint(); // your paint
long startTime;
public MyView(Context context) {
super(context);
// start the animation:
this.startTime = System.currentTimeMillis();
this.postInvalidate();
}
@Override
protected void onDraw(Canvas canvas) {
long elapsedTime = System.currentTimeMillis() - startTime;
matrix.postRotate(30 * elapsedTime/1000); // rotate 30° every second
matrix.postTranslate(100 * elapsedTime/1000, 0); // move 100 pixels to the right
// other transformations...
canvas.concat(matrix); // call this before drawing on the canvas!!
canvas.drawPath(path, paint); // draw on canvas
if(elapsedTime < animationDuration)
this.postInvalidateDelayed( 1000 / framesPerSecond);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句