Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a fraction in android studio

How to do I write a fraction in android studio. What's the best practice for a fraction with a horizontal line I am trying to produce.

like image 251
user4914918 Avatar asked Oct 01 '15 13:10

user4914918


3 Answers

Use html format. 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");
like image 157
Zahan Safallwa Avatar answered Oct 20 '22 23:10

Zahan Safallwa


You can try this solution: http://blog.sqisland.com/2014/11/android-stacked-fractions.html

Basically, you have to looking for a font that supports afrc. Now, you can play with your TextViews and TagHandlers until you get the result desired.

like image 2
Mou Avatar answered Oct 21 '22 01:10

Mou


The solution does not seem simple, however if you want to try fraction in xml, go to this website.

http://unicode-search.net/unicode-namesearch.pl?term=fraction

This code worked for me to show 14.

The xml code is.

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="\u00BC"
            android:id="@+id/textView"
            android:textSize="25sp" />

The required line is android:text="\u00BC" to show 14 as fraction.

So if you want to show 12 or any other as fraction from the above mentioned website, just append the last two characters(in this case BD) to \u00.

So 1/2 becomes \u00BD

like image 1
penta Avatar answered Oct 20 '22 23:10

penta