Android:在画布上对单个路径的 alpha 进行动画处理
我想在 Android 画布上为单个路径设置动画。
public class MyView extends View {
private Path paths[];
protected void onDraw( Canvas canvas ) {
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth( 8 );
paint.setColor(Color.BLUE);
Path path = new Path();
path.moveTo(75, 11);
path.quadTo(62, 87, 10, 144);
canvas.drawPath( path, paint );
paths[0] = path;
path.reset();
path.moveTo(50, 100);
path.lineTo(150, 200);
canvas.drawPath( path, paint );
paths[1] = path;
}
}
现在我有路径[],我想分别为每个路径设置动画。我希望它能改变阿尔法,就像它在增长一样。起初只有一个小点,然后它长成一条线,重复。
能做到吗?
如何?
I would like to animate a single Path on the android canvas.
public class MyView extends View {
private Path paths[];
protected void onDraw( Canvas canvas ) {
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth( 8 );
paint.setColor(Color.BLUE);
Path path = new Path();
path.moveTo(75, 11);
path.quadTo(62, 87, 10, 144);
canvas.drawPath( path, paint );
paths[0] = path;
path.reset();
path.moveTo(50, 100);
path.lineTo(150, 200);
canvas.drawPath( path, paint );
paths[1] = path;
}
}
Now I have paths[], I would like to animate each one separately. I would like it to change alpha like it was growing. At first there is just a little dot, then it grows into a line, repeat.
Can it be done?
How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将添加一个范围从 0 到 1 的新浮点数,以保留当前动画百分比并使用它来设置当前的 alpha
I would add a new float ranging from 0 to 1 that keeps the current animation percentage and use it to set the current alpha