我使用以下代码绘制文字,
public void drawText(Canvas canvas, int _x, int _y, float scale, float rotate) {
if (TextUtils.isEmpty(mText)) {
return;
}
int x = _x;
int y = _y;
mPaint.getTextBounds(mText, 0, mText.length(), mTextRect);
mTextRect.offset(x - (mTextRect.width() >> 1), y);
mHelpBoxRect.set(mTextRect.left - PADDING, mTextRect.top - PADDING
, mTextRect.right + PADDING, mTextRect.bottom + PADDING);
RectUtil.scaleRect(mHelpBoxRect, scale);
canvas.save();
canvas.scale(scale, scale, mHelpBoxRect.centerX(), mHelpBoxRect.centerY());
canvas.rotate(rotate, mHelpBoxRect.centerX(), mHelpBoxRect.centerY());
canvas.drawText(mText, x, y, mPaint);
canvas.restore();
}
以下是scaleRect方法,
public static void scaleRect(RectF rect, float scale) {
float w = rect.width();
float h = rect.height();
float newW = scale * w;
float newH = scale * h;
float dx = (newW - w) / 2;
float dy = (newH - h) / 2;
rect.left -= dx;
rect.top -= dy;
rect.right += dx;
rect.bottom += dy;
}
问题在于,如果文本是多行的,则文本不会换行。如果是多行文本,我怎么能让文本换行?