2017-06-19 3 views
0

Kann mir jemand helfen, unter Menge String-Format in Android-Anwendung zu erreichen.Format Menge Zeichenfolge

enter image description here

+1

Dies erfordert wahrscheinlich eine spezielle Schriftart für das erhöhte Dollarzeichen und die Nullen. –

Antwort

7

Android-Smartphones unterstützen einen beliebigen Text in tief- oder hochgestellte schreiben. können Sie versuchen, mit

Html.fromHtml("<sup>$</sup>1,500<sup>00</sup>"); 

Ohne Verwendung HTML Tag Sie besuchen können Subscript and Superscript a String in Android

+1

Es funktioniert, aber ich brauche die Lösung außer HTML-Tags. –

+2

@ V.J. schauen Sie hier zum Beispiel https://Stackoverflow.com/a/8872986/3383038 –

+1

@OlegOsipenko Gute Infos. –

1

// Für die Hoch- und Tief Sie können

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)); 
    } 
1

Gerade Hilfe von HTML-Tag nehmen Kopieren Sie es in Ihrem 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> 
+0

@ V.J. Wenn es das ist, was Sie brauchen, akzeptieren Sie es bitte –

+2

Ohhh Entschuldigung. Es ist ein guter Versuch, aber nicht für mich arbeiten. Da ich auch mein Layout ändern muss .. –

Verwandte Themen