0

There are 2 places where I am displaying a text message. One is on a textview the other is a View which draws text.

now my main problem is that If I do a setTextSize in TextView to 20, the font appears bigger to the paint.setTextSize which is what canvas.drawText Uses

How to make them look same?

Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

1

This is due to some confusing parts of the TextView API. setTextSize expects a SP (scaled pixels) value, while getTextSize returns the text size in pixels.

You want to set the size to 20 pixles, because Paint uses pixels for its text size, so you need to call setTextSize(int unit, float size).

Your method call should look something like this: setTextSize(TypedValue.COMPLEX_UNIT_PX, 20)

I've linked the method definition so you can check it out for yourself and see exactly what's going on.

Edit: The question you asked me in the comments section has already been answered on StackOverflow. Check it out.

Community
  • 1
  • 1
npace
  • 4,218
  • 1
  • 25
  • 35
  • thanks. But i have done all my setting wrt to how it looks with TextView. So what is the way to get the caluclation which Textview does internally to convert 20 to some other value, I can use the same logic for Draw –  Dec 05 '13 at 13:00