Android TextView's subscript being clipped off

前端 未结 9 2327
粉色の甜心
粉色の甜心 2020-12-28 14:41

The Android TextView clips off my text subscripts (see image below) even when I use android:layout_height=\"wrap_content\" for the TextView. Is there a fix/work

相关标签:
9条回答
  • 2020-12-28 15:26

    I had the same issue, so after reading the posts, I found this to be working.

    Example : H2O
    simply use :

    textView.setText(Html.fromHtml("H<sub>2</sub>O"),BufferType.SPANNABLE);
    

    BufferType.SPANNABLE is important as it will tell textview to consider the superscript span.

    If you are using custom tag handler for HTML you can also use it like this:

     textView.setText(Html.fromHtml(data, null, new CustomHtmlTagHandler(),BufferType.SPANNABLE);
    

    Hope it helps someone looking for same problem.

    0 讨论(0)
  • 2020-12-28 15:28

    This worked for me along with the Small tag.

    1. Inside the TextView add

    android:paddingBottom="1dp"

    1. Use the small Tag after the subscript

    yourTextView.setText(Html.fromHtml("" +" Hey< sub >< small >2< /small > < /sub >"));

    Note Please note , step 1 is important , My text was still cutting down in some case,using paddingBottom resolved it. Don't forget to remove the spaces in sub and small tags that are present in my answer :)

    0 讨论(0)
  • 2020-12-28 15:33

    android:lineSpacingExtra="4dp" should solve it this will add extra line spacing below your text, and keep subscript from getting cutoff. I haven't tried it with superscript so it might now fix that.

    0 讨论(0)
提交回复
热议问题