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-around for this?
P/S: Superscripts work fine
Note: padding doesn't work.
- I tried even adding a padding of 50dip but it did not help.
- I can use an absolute height such as 50dip but that messes everything up when I need text to wrap around.
Sample Code:
mtTextView.setText(Html.fromHtml("HC0<sub>3</sub>"));
I had the same issue, so after reading the posts, I found this to be working.
Example : H2O
simply use :
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:
Hope it helps someone looking for same problem.
I have faced the same issue in ICS and below android versions. I fixed the issue by a simple step
Give a minimum height to the Text View . It will fix the problem.
You can set minimum height through xml .
Or dynamically
This worked for me along with the Small tag.
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 :)
For subscript a slight variation to the above suggestion is needed, two small tags:
The More number of <small> </small> tags in there, the smaller the subscript will get and you should be able to see it without being clipped.
Eg: H2O
Most answers suggest to add paddings or to use smaller sub/superscripts. These might be serviceable workarounds, but they don't really solve the problem. Ideally, we want Android to take the sub/superscript into account when calculating line height. I think I found how to do it, and I'm sharing it for people googling this issue.
The trick is in BufferType.SPANNABLE. Apparently it makes TextView pay more attention to the markup and calculate line heights properly.