1

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?

Community
  • 1
  • 1
qulfille
  • 208
  • 3
  • 13

6 Answers6

1

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: ¼½¾

swinefeaster
  • 2,525
  • 3
  • 30
  • 48
1
chm2.setText(Html.fromHtml("<sup>12</sup>&frasl;<sub>6</sub>"));

or

chm5.setText(Html.fromHtml("<u>1</u><br/>" +
            "&emsp;2"));

here

&emsp;

is used for giving space infront of second line for compatible position

0

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.

Sergi Juanola
  • 6,531
  • 8
  • 56
  • 93
0

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]
swinefeaster
  • 2,525
  • 3
  • 30
  • 48
0

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.

0

in a string, you can use Unicode in 'U\00BC' this way that is (1/4).

Rince Mathew
  • 27
  • 1
  • 6