我正在使用以下代码制作一个微调器。
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
for (int i = 0; i < segmentColors.length; i ++)
{
drawDataSet(canvas, i);
}
canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth() - getWidth()/2 - dpToPx(5), mTransparentCirclePaint);
}
protected void drawDataSet(Canvas canvas, int position)
{
int color = segmentColors[position];
float mainArcAngle = ((float) 360/ (float)segmentColors.length);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
if ( position%2 == 0)
paint.setColor(color);
else
paint.setColor(Color.parseColor("#009f2f"));
RectF rect = new RectF(0, 0, getWidth(), getWidth());
canvas.drawArc(rect, (mainArcAngle * position), mainArcAngle, true, paint);
TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.BLACK);
mTextPaint.setAntiAlias(true);
mTextPaint.setTypeface(Typeface.MONOSPACE);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.setTextSize(18f);
Path path = new Path();
path.addArc(rect, (mainArcAngle * position), mainArcAngle);
//PathMeasure pm = new PathMeasure(path, false);
//DynamicLayout layout = new DynamicLayout(values[position], values[position], mTextPaint, (int) pm.getLength(), Layout.Alignment.ALIGN_CENTER, 1, 0, true);
//canvas.save();
//layout.draw(canvas);
//canvas.restore();
canvas.drawTextOnPath(values[position], path, 0 , getWidth() / 6 , mTextPaint );
}
由于间距很小,在弧内写入的文本有点压缩。如何使它成为多行或增加字母间距?