This sounds like a job for Spannable
. As you've noticed the problem with doing two views is that the bounds of the TextView
in your two line example is still a rectangle, so laying out the second view at the end of the text gets tricky. HTML can work for simple tags (bold, underline, headings), but isn't too flexible.
The solution is to use Spannable
to create the text ouf of pieces of content with specific formatting applied to each "span". As it turns out, then you can just stick the whole results right into a single TextView
. Something like:
TextView tv; //Defined somewhere else
SpannableStringBuilder resultBuilder = new SpannableStringBuilder();
SpannableString item = new SpannableString("Long and Fancy Movie Title Here");
item.setSpan(new AbsoluteSizeSpan(18, true), 0, item.length(), 0);
resultBuilder.append(item);
SpannableString item = new SpannableString("(2011)");
item.setSpan(new AbsoluteSizeSpan(12, true), 0, item.length(), 0);
resultBuilder.append(item);
tv.setText(resultBuilder, TextView.BufferType.SPANNABLE);
There are a ton of different span definitions in android.text.style
, the above is just an example to create two different text sizes in the same string. You should be able to get what you want out of this one, TextAppearanceSpan
, TypefaceSpan
, or some other combination.
HTH