Measure text in canvas with stroke - Android

20 Views Asked by At

I'm trying to make a custom textview and I'm struggling to measure my stroked text. I know that a text size can be easily determined using

 TEXT_PAINT.getTextBounds(text, 0, text.length(), bounds);

However, I have a paint that draws a stroke around the text.

    WHITE_BORDER_PAINT = new Paint();
    WHITE_BORDER_PAINT.setTypeface(font);
    WHITE_BORDER_PAINT.setTextSize(textSize);
    WHITE_BORDER_PAINT.setStyle(Paint.Style.STROKE);
    WHITE_BORDER_PAINT.setStrokeWidth(bigBorderSize);
    WHITE_BORDER_PAINT.setColor(context.getColor(R.color.white));

I'd like to know how to determine the bounds of that drawing, as getTextBounds is returning 0 for WHITE_BORDER_PAINT

0

There are 0 best solutions below