How to write a piece in Android studio

How to write fraction in Android studio. What is the best practice for a horizontal line fraction that I am trying to create.

+5
source share
3 answers

Use the html format. However, you must add extra space above and below so that it is not cut off.

SpannableStringBuilder test = new SpannableStringBuilder(); test.append("\n"); test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>")); test.append("\n"); 
+3
source

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

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

+2
source

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

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

This code worked for me to show 1 & frasl; 4 .

Xml code.

 <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" /> 

Required android:text="\u00BC" string android:text="\u00BC" to show 1 & frasl; 4 as a fraction.

So, if you want to show 1 & frasl; 2 or any other as a fraction from the above website, just add the last two characters (in this case BD ) to \u00 .

So 1/2 becomes \ u00BD

0
source

Source: https://habr.com/ru/post/1232717/


All Articles