Reputation: 1269
I can't seem to figure out a way to easily display a fraction in a textview. Let be more clear i need a fraction with a number over a number in a textview and then there should be able to add more text after that all in the same textview. I have seen this linke Android - displaying fractions using unicode
And the solution does not work great especially when playing it into a alertdialog the formating is lost.
I have also tried this
SpannableStringBuilder test = new SpannableStringBuilder();
SpannableString content = new SpannableString("3");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
test.append(content);
test.append("\n");
test.append("56");
This works great however if I need to add more to that line it will be displayed on the bottom and i need it on the top line. If i try to insert into the top line then the bottom line will move because the textview is centered (also it wont work by aligning the text view in any particular way since i may have text before the fraction).. *I do not want multiple textview
Upvotes: 2
Views: 2271
Reputation: 1269
The solution was to use this html format from the link. However you must add a extra space on the top and bottom to keep it from being cut off.
SpannableStringBuilder test = new SpannableStringBuilder();
test.append("\n");
test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
test.append("\n");
Upvotes: 2