Android TextView setTextSize incorrectly increases text size -


this in extension of textview. gettextsize() , settextsize() not overridden, not extend methods. programming in 1.6, api level 4.

the loop in code causes size multiplied 1.5 every time iterates, e.g. if size reads 200 gettextsize, settextsize(size) called, gettextsize called again reads 300.

public void shrinktest() {     float size = this.gettextsize();      while (size > 8) {         this.settextsize(size);         size = this.gettextsize();     } } 

why this?

heh, mixed units problem. seems little counterintuitive, it's easy fix. default method settextsize(float) assumes you're inputting sp units (scaled pixels), while gettextsize() method returns exact pixel size.

you can fix using alternate settextsize(typedvalue, float), so:

this.settextsize(typedvalue.complex_unit_px, size); 

this make sure you're working same units.


Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -