伙计们 我尝试实现弧头上的黑色箭头。箭头以弧形动画,并具有圆形轨迹。我已经根据不同的值用动画实现了红色弧线。 请参阅附件。 如何在红色圆弧上实现黑色箭头?因为如果我采用与红色弧形动画相同的方式,黑色箭头将打印不需要的轨迹。
提前致谢! 里昂
最佳答案
您只需要 Canvas。
这是例子。
这是你的绘图类:
public class CircleView extends View
{
public CircleView(Context context) {
super(context);
path = new Path();
paint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float angle = 270;
float radius = canvas.getWidth()/3;
float x = canvas.getWidth()/2;
float y = canvas.getHeight()/2;
final RectF oval = new RectF();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(25);
oval.set(x - radius, y - radius, x + radius,y + radius);
// Draw circle
paint.setColor(Color.RED);
canvas.drawArc(oval, 135, angle, false, paint);
paint.setColor(Color.BLUE);
canvas.drawArc(oval, angle, 405-angle, false, paint);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.BLACK);
float l = 1.2f;
float a = angle*(float)Math.PI/180;
// Draw arrow
path.moveTo(x+ (float)Math.cos(a) *radius, y + (float)Math.sin(a) * radius);
path.lineTo(x+ (float)Math.cos(a+0.1) *radius*l, y + (float)Math.sin(a+0.1) * radius*l);
path.lineTo(x+ (float)Math.cos(a-0.1) *radius*l, y + (float)Math.sin(a-0.1) * radius*l);
path.lineTo(x+ (float)Math.cos(a) *radius, y + (float)Math.sin(a) * radius);
canvas.drawPath(path, paint);
}
private Path path;
private Paint paint;
}
这是它的 Activity :
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new CircleView(this));
}
}
对于 angle == 200 你会看到这样的图像:
IntelliJ Idea 的工作副本:https://github.com/weerf/android_circle
关于android - 如何在 canvas android 上绘制带动画的圆形轨迹箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29489123/