Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust line height in TextView with multiple type sizes?

Tags:

I have a TextView that holds a Spannable string. The string contains a bunch of text, the first word of which is double the typesize as the rest of the string.

The problem is that the line spacing between the first and second line is much larger than the line spacing between subsequent lines due to the increased size of the first word.

http://img.skitch.com/20100615-fwd2aehbsgaby8s2s9psx3wwii.png

The spannable string was created using the following code snippet:

    // Price     CharSequence text = "$30 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."     final Pattern priceRegex = Pattern.compile("^(.[0-9]+)\\s.*");     final Matcher m = priceRegex.matcher(text!=null ? text : "");     if( m.matches() ) {         text = new SpannableString(text);         ((SpannableString)text).setSpan(new RelativeSizeSpan(2), 0, m.end(1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);     } 

How can I fix my TextView so that all lines have the same spacing?

like image 253
emmby Avatar asked Jun 15 '10 15:06

emmby


1 Answers

You can try using one of these TextView properties:

android:lineSpacingMultiplier android:lineSpacingExtra 

to at least try to make all lines the same height (same as the first one).

like image 120
Rangel Reale Avatar answered Oct 29 '22 20:10

Rangel Reale