如何调整行高在TextView中有多个类型的大小? [英] How to adjust line height in TextView with multiple type sizes?

查看:140
本文介绍了如何调整行高在TextView中有多个类型的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView的持有Spannable字符串。该字符串包含一堆文字,其中的第一个字是双typesize作为字符串的其余部分。

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.

使用以下code段创建的spannable字符串:

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);
    }

我怎样才能解决我的TextView,使所有线路具有相同的间距?

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

推荐答案

您可以尝试使用这些TextView的属性之一:

You can try using one of these TextView properties:

安卓lineSpacingMultiplier 机器人:lineSpacingExtra

android:lineSpacingMultiplier android:lineSpacingExtra

要至少尝试使所有行相同的高度(同第一个)。

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

这篇关于如何调整行高在TextView中有多个类型的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆