When I click on the button, the font size shrinks to 12. However, the result is :
Maybe setting the view to View.GONE, changing your text size, then setting to View.VISIBLE would work?
Finally, I found the reason/solution!!!
This is a known bug for Android 3.1+
Issue 17343
Issue 22493
Possible workaround are:
text.setText(text+"\n");
or
final String DOUBLE_BYTE_SPACE = "\u3000";
text.setText(text + DOUBLE_BYTE_SPACE);
Instead of using:
final String DOUBLE_BYTE_SPACE = "\u3000";
text.setText(text + DOUBLE_BYTE_SPACE);
Better use:
final String DOUBLE_BYTE_WORDJOINER = "\u2060";
text.setText(text + DOUBLE_BYTE_WORDJOINER);
Extra information: Word Joiner is 0 width space.
I found that adding the character "\u200b" does not appear as a broken character, nor does it add a whitespace/linebreak.
For more details on the "ZERO WIDTH SPACE" see: http://www.fileformat.info/info/unicode/char/200b/index.htm
So, After a long search I have found a solution. Every time you set text do:
setText("I am a Text",TextView.BufferType.SPANNABLE);
Or after resizing your text just do:
setText(getText(),TextView.BufferType.SPANNABLE);
In main.xml file TextView size given android:textSize="40sp" . and in side java, click on the button change the value here
public void onClick(View v) {
text.setTextSize(12);
}