Android:TextView height doesn't change after shrinking the font size

后端 未结 7 1210
长情又很酷
长情又很酷 2020-12-03 14:19

When I click on the button, the font size shrinks to 12. However, the result is :

\"enter

相关标签:
7条回答
  • 2020-12-03 14:57

    Maybe setting the view to View.GONE, changing your text size, then setting to View.VISIBLE would work?

    0 讨论(0)
  • 2020-12-03 14:58

    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);
    
    0 讨论(0)
  • 2020-12-03 15:05

    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.

    0 讨论(0)
  • 2020-12-03 15:07

    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

    0 讨论(0)
  • 2020-12-03 15:08

    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);
    
    0 讨论(0)
  • 2020-12-03 15:10

    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);
            }
    
    0 讨论(0)
提交回复
热议问题