Can anyone help me to achieve below amount string format in android application.
Asked
Active
Viewed 89 times
3 Answers
7
Android smartphones support writing any text in subscript or superscript . You can try with
Html.fromHtml("<sup>$</sup>1,500<sup>00</sup>");
Without using HTML tag You can visit Subscript and Superscript a String in Android

IntelliJ Amiya
- 74,896
- 15
- 165
- 198
-
2@V.J. look here for example https://stackoverflow.com/a/8872986/3383038 – Oleg Osipenko Jun 19 '17 at 06:47
-
1
-
1IntelliJAmiya @OlegOsipenko Nice Tutorial. There is a lot of ideas to achieve this type of string output. – V.J. Jun 19 '17 at 06:52
1
// For the superscript and subscript you can take help of html tag
String yourText="$1,050<sup>00</sup>";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
yourTextView.setText(Html.fromHtml(yourText,Html.FROM_HTML_MODE_LEGACY))
} else {
yourTextView.setText(Html.fromHtml(yourText));
}

Dhaval Solanki
- 4,589
- 1
- 23
- 39
1
Just Copy past it inside your layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:layout_height="match_parent">
<TextView
android:id="@+id/dollar"
android:text="$"
android:textSize="40dp"
android:gravity="top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_toRightOf="@+id/dollar"
android:id="@+id/ammount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="80dp"
android:layout_marginTop="-10dp"
android:text="1,050"/>
<TextView
android:layout_toRightOf="@+id/ammount"
android:id="@+id/zeroes"
android:text="00"
android:textSize="40dp"
android:gravity="top"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

Shohruh Abduakhatov
- 84
- 1
- 11
-
2Ohhh sorry. It is Good try but not work for me. As i have to change my layout too.. – V.J. Jun 19 '17 at 07:14