2

我需要在 android 中显示一个带有文本的弧。假设文本应该是白色的,而弧应该用红色背景填充。我通过使用addArc()方法成功地在弧中显示文本,但无法填充弧的背景。我在我的onDraw()方法中使用了以下代码:

path = new Path();
path.addArc(rect, 0, 60); 
paint6 = new Paint(Paint.ANTI_ALIAS_FLAG); 
paint6.setStyle(Paint.Style.FILL_AND_STROKE); 
paint6.setColor(Color.BLACK);
paint6.setTextSize(20f);
paint2.setStrokeWidth(mRadius/2);
paint2.setStrokeCap(Paint.Cap.BUTT);
canvas.drawTextOnPath("Hello", path, 0, 20, paint6);

谁能帮我解决这个问题?

4

1 回答 1

3

我自己找到了答案

     Paint mPaint = new Paint();
    mPaint.setColor(Color.GREEN);
    Path mPath = new Path();
    mPath.addArc(rect, 0, 60);
    mPaint.setStrokeWidth(mRadius/2);
    mPaint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(mPath, mPaint);

    mPaint.setColor(Color.BLUE);
    mPaint.setStrokeWidth(mRadius/2);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(20);
    canvas.drawTextOnPath("Draw ", mPath, 0, 20, mPaint);
于 2012-12-06T20:36:47.783 回答