0

I have used the following code to draw text,

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

Following is scaleRect method,

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

The issue is that, the text is not wrapping in case if it is of multiline. How will I be able to let the text wrap in case of multi line text?

  • 2
    see `android.text.Layout` documentation – pskink Mar 22 '17 at 13:24
  • [Paginating text in Android](http://stackoverflow.com/questions/31837840/paginating-text-in-android/32096884#32096884) might be helpful. – Onik Mar 22 '17 at 17:43

0 Answers0