Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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);
like image 571
Zeus Monolitics Avatar asked Feb 11 '13 23:02

Zeus Monolitics


Video Answer


2 Answers

What about:

float px = editext.getTextSize();
float sp = px / getResources().getDisplayMetrics().scaledDensity;
like image 154
t0m Avatar answered Nov 03 '22 01:11

t0m


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.

like image 28
dmon Avatar answered Nov 03 '22 00:11

dmon