Reputation: 208
I want to display fraction in android. But it is displayed as 1/2. I don't want this. I want exactly how described here in this question.
how is it possible to get it in TextView?
Upvotes: 1
Views: 8737
Reputation: 27
in a string, you can use Unicode in 'U\00BC' this way that is (1/4).
Upvotes: 0
Reputation: 89
chm2.setText(Html.fromHtml("<sup>12</sup>⁄<sub>6</sub>"));
or
chm5.setText(Html.fromHtml("<u>1</u><br/>" +
" 2"));
here
 
is used for giving space infront of second line for compatible position
Upvotes: 1
Reputation: 31
You can create a layout as follows
<RelativeLayout
android:id="@+id/RelativeLayout"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="0"
android:textColor="@color/gray"
android:textSize="14sp" />
<TextView
android:id="@+id/textSlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toRightOf="@+id/textTop"
android:text="/"
android:textColor="@color/gray" />
<TextView
android:id="@+id/textBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textSlash"
android:layout_gravity="right"
android:layout_toRightOf="@+id/textSlash"
android:text="10"
android:textColor="@color/gray"
android:textSize="14sp" />
</RelativeLayout>
I'm sure this can be improved on - but gives the basic idea.
Upvotes: 0
Reputation: 2555
Depending on your requirements, you could also achieve this by using 3 TextViews and a Shape to draw the line (a rectangle):
|---------- | [topTextView]
| |
|bigTextView| ---[rectangle shape]---
| |
|---------- | [bottomTextView]
Upvotes: 0
Reputation: 6647
I hardly think so. A TextView
shows text. That's almost everytime done using specific representation languages (like HTML, but for math), and thus your input would only show the representation language (with the tags and so) if it is unable to understand it, and not the resulting formula.
Upvotes: 0
Reputation: 2555
Why don't you use a WebView and the html code as described in your linked question?
http://developer.android.com/reference/android/webkit/WebView.html
For a limited subset, you could also use the following unicode characters in a TextView: ¼½¾
Upvotes: 1