2012-12-06 26 views
2

我需要在android中顯示弧線,並在其中顯示文本。讓我們說文字應該是白色的,因爲圓弧應該填充紅色背景。通過使用addArc()方法,我成功地在圓弧中顯示文本,但無法填充圓弧的背景。我用下面的代碼在我onDraw()方法:如何在Android中使用文本顯示弧線

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); 

誰能幫我整理出這個問題?

回答

2

,我發現自己的答案

 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); 
相關問題