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.
On Sunday, May 6, 2012 12:58:06 PM UTC+8, x300 wrote:
>
> Thanks.
> I will play with SpannableString stuff with SizeSpan, and will post
> here if something works.
>
> I often get across your post as a solution to similar problems I'm
> facing, and want you to know that your efforts are appreciated around
> the globe (I am located in Tokyo).
>
> Why don't you write a book "Curious Coder's Guide to Dark Side of
> Android"? I am sure there are many tricks that expand the horizon
> into territories where Android is not initially intended to be, and
> the ever advancing hardware capabilities certainly warrant such probes
> to change the course of core development in the future.
>
> In my opinion, conserving precious display area is something Android
> "should" excel for mobile computing, but does not.
>
>
> > Yeah, you'll have to do it the hard way, using SpannableString or
> > SpannableStringBuilder, using an AbsoluteSizeSpan or a
> > RelativeSizeSpan to change the font sizes. This is more tedious and
> > wordy, but has the advantage of being faster and not being tied to the
> > implementation of fromHtml().
> >
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com|
> http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> >
> > _The Busy Coder's Guide to Android Development_ Version 3.7 Available!
--
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