20

I`ll wish change the text size in run-time based in the old size.

How get a text size in SP (Scaled Pixel) directly from a TextView?

Something like:

textMove.setTextSize(textMove.getTextSPSize()  + sizeFontScale);
Zeus Monolitics
  • 832
  • 9
  • 19

2 Answers2

31

What about:

float px = editext.getTextSize();
float sp = px / getResources().getDisplayMetrics().scaledDensity;
t0m
  • 3,004
  • 31
  • 53
11

So... setTextSize(int) actually assumes Scaled Pixels. getTextSize() returns the actual pixels. If you want to increase by an amount of actual pixels then you can call getTextSize(), add whatever, then call setTextSize(TypedValue.COMPLEX_UNIT_PX, newValue). I guess I'm kind of wondering if you really want to do everything in Scaled Pixels.

dmon
  • 30,048
  • 8
  • 87
  • 96