Ilya Izhovkin
Ilya Izhovkin

Reputation: 3465

Android: Improper text scaling when draw text on canvas

I am drawing formatted text on canvas using DynamicLayout, and I need to implement some sort of zooming. I tried to use canvas.scale(...) for it. But when text contains highlights, text is scaled inconsistent with background, like this:

scaled text with highlight

Code which draws text is very simple:

canvas.scale(zoom, zoom);
TextPaint textPaint = new TextPaint();
textPaint.setAntiAlias(true);
DynamicLayout layout = new DynamicLayout(text, textPaint, width,
                            Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, false);
layout.draw(canvas);

How to make it right way?

Upvotes: 5

Views: 1329

Answers (1)

Ilya Izhovkin
Ilya Izhovkin

Reputation: 3465

I've solved this issue, setting textPaint.setSubpixelText(true);

Upvotes: 5

Related Questions