Mar*_*raj 11 animation android bitmap gauge porter-duff
好的,所以我一直试图这样做几天,我没有在哪里.所以我有以下两个图像:
第一个是RPM Gauge

第二幅图像是一个全白图形,表示rpm规格已满:

我想做以下事情:

我有用户输入工作,我需要动画的帮助.这是我尝试过的:
我知道可能有一种更简单或更有效的方法,我只是没有线索.任何有好主意的人?
*注意所有图像都是PNG
提前致谢!
正如你已经发现的,我会使用剪辑:
我会用
Canvas.clipPath()
Run Code Online (Sandbox Code Playgroud)
路径看起来像在圆心开始的馅饼切片,像这样:

要创建剪辑路径,请使用以下内容:
public class PieView extends View {
private int width = 200;
private int angleStart = 135;
private int sweep = 270;
private Path p;
private Paint paint = new Paint();
public PieView(Context context, AttributeSet attrs) {
super(context, attrs);
p = new Path();
//move into center of the circle
p.setLastPoint(width/2, width/2);
//add line from the center to arc at specified angle
p.lineTo(width/2+(float)Math.cos(Math.toRadians(angleStart))*(width/2),
width/2+(float)Math.sin(Math.toRadians(angleStart))*(width/2));
//add arc from start angle with specified sweep
p.addArc(new RectF(0, 0, width, width), angleStart, sweep);
//from end of arc return to the center of circle
p.lineTo(width/2, width/2);
paint.setColor(Color.RED);
paint.setStrokeWidth(1);
paint.setStyle(Style.STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0,0,width,width, paint);
canvas.drawPath(p,paint);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13160 次 |
| 最近记录: |