2017-06-19 58 views
0

誰能幫助我實現以下金額字符串格式Android應用程序。格式金額字符串

enter image description here

+1

這可能需要募集的美元符號和零專門的字體。 –

回答

7

Android智能手機支持標或上標寫任何文字。 您可以

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

儘量不使用HTML標籤,您可以訪問Subscript and Superscript a String in Android

+1

它的工作原理,但我需要的解決方案,除了HTML標籤。 –

+2

@ V.J。看這裏例如https://stackoverflow.com/a/8872986/3383038 –

+1

@OlegOsipenko良好的信息。 –

1

//對於標和下標可以採取HTML標記的幫助下

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

剛過去,它複製您的佈局中:

<?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。如果是你需要的,請接受 –

+2

哦對不起。這是良好的嘗試,但不適合我。因爲我不得不改變我的佈局。 –