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

哦对不起。这是良好的尝试,但不适合我。因为我不得不改变我的布局。 –