jeudi 7 mai 2015

How to set three different textsize in single textview in android

I want to set the three different text size in single textview as like the below image sample,enter image description here

I have tried with Html as like the below,

 StringBuilder fontString = new StringBuilder();

    fontString.append("<small>");
    fontString.append("1.78");
    fontString.append("</small>");      
    fontString.append("<big><b>");
    fontString.append("33");
    fontString.append("</b></big>");        
    fontString.append("<sup>");
    fontString.append("<small>");
    fontString .append("2");
    fontString.append("</small>");
    fontString.append("</sup>");

Also I tried SpannableString formatting,

SpannableString  spanString = new SpannableString("1.34456");
    spanString.setSpan(new RelativeSizeSpan(1.75f), 0,spanString.length()-2-1, 0);
    spanString.setSpan(new StyleSpan(Typeface.BOLD), spanString.length()-2-1, spanString.length()-1, 0);
    spanString.setSpan(new ForegroundColorSpan(Color.RED), spanString.length()-2-1,  spanString.length()-1, 0);     
    spanString.setSpan(new RelativeSizeSpan(3f), spanString.length()-2-1, spanString.length()-1, 0);        
    spanString.setSpan(new RelativeSizeSpan(1.25f), spanString.length()-1, spanString.length(), 0);

like the below mentioned image, enter image description here

Please suggest me if you know the solution,I have tried with superscript or subscript also but no luck.

Aucun commentaire:

Enregistrer un commentaire