Using spannables directly is certainly the better way to do it since the 
supported html tags apparently are not clearly specified as Mark already 
mentioned.

However, out of curiosity, I looked at the source of Html.java. So, just 
for the sake of completeness: I found that <font> apparently only supports 
the attributes "color" and "face", but not "size". I also found that it 
supports "<big>" and "<small>", i.e. using an html string like 
"<big>199</big> <small>km/h</small>" seems to work, although you cannot 
specify the sizes exactly...

Am Sonntag, 6. Mai 2012 09:53:17 UTC+2 schrieb x300:
>
> It works! 
> Thanks a lot for sharing your insight :)  :)  :)    My code look as 
> follows: 
>
>         private static final float SMALL_TEXT_RELATIVE_SIZE = 0.6f; 
>
>         public CharSequence setSpeedText(){ 
>                         CharSequence text = "km/h"; 
>                 SpannableStringBuilder smaller = new 
> SpannableStringBuilder(text); 
>                 smaller.setSpan(new 
> RelativeSizeSpan(SMALL_TEXT_RELATIVE_SIZE), 0, 
>                 text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
>                         CharSequence cs = TextUtils.concat(kMph[DID], 
> smaller); 
>
>                 return cs; 
>         } 
>
> and the result is displayed beautifully with large "45.6" sitting next 
> to small "km/h" as I always wanted them to. 
>
> Thank you very very much! 
>
>
> On May 6, 3:26 pm, Zsolt Vasvari <[email protected]> wrote: 
> > Here's the code I use to make an arbitrary CharSequence "smaller" 
> > 
> >     private static final float SMALL_TEXT_RELATIVE_SIZE = 0.8f; 
> > 
> >     public static CharSequence makeSmaller(CharSequence text) 
> >     { 
> >         SpannableStringBuilder smaller = new 
> SpannableStringBuilder(text); 
> >         smaller.setSpan(new RelativeSizeSpan(SMALL_TEXT_RELATIVE_SIZE), 
> 0, 
> > text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
> > 
> >         return smaller; 
> >     } 
> > 
> > Once you have the "smaller" text, you can use TextUtils.concat() to 
> build 
> > up you final text.  Just make sure you nowhere cast/toString() the 
> > CharSequence to a String because you will lose the formatting info. 
> > 
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to