SpannableString:是否可以申请两个或两个以上RelativeSizeSpans? [英] SpannableString: Is it possible to apply two or more RelativeSizeSpans?

查看:1004
本文介绍了SpannableString:是否可以申请两个或两个以上RelativeSizeSpans?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个SpannableString,使得它看起来是这样的:

I am trying to construct a SpannableString such that it looks like this:

两个字符(M,S)应该比其余小。 我试图容纳所有文字于一体SpannableString,我也尝试过通过SpannableStringBuilder来连接两个SpannableStrings。 在code一Spannable看起来是这样的:

Two characters (m, s) should be smaller than the rest. I have tried to hold all the text in one SpannableString, and I also tried to concatenate two SpannableStrings via a SpannableStringBuilder. The code for one Spannable looks like this:

spannable.setSpan(new RelativeSizeSpan(0.75f), spannable.length() - 1, spannable.length(), 0);

但是,只有一个格式应用于 - 使用时SpannableStringBuilder,只有m为更小的,并且使用一个SpannableString为整个文本时,只有s为更小的

However, only one formatting is applied - when using the SpannableStringBuilder, only the "m" is smaller, and when using one SpannableString for the whole text, only the "s" is smaller.

调试还表明Spannables似乎保持RelativeSizeSpan只有一个实例,这意味着可以存在的一种类型的只有一个跨度。这是真的还是正常现象? 难道是可取的串联TextViews呢?

Debugging also showed that Spannables seem to hold only one instance of RelativeSizeSpan, meaning there can be only one Span of one type. Is this true or expected behaviour? Would it be advisable to concatenate TextViews instead?

编辑:顺便说一句,我想删除一个HTML.fromHtml()调用这里因为性能原因(多GC话费)

By the way, I am trying to remove a HTML.fromHtml() call here for performance reasons (many GC calls).

推荐答案

如果你还在寻找一个答案,我可能有一个解决方案。我有类似的问题。我用文本实用程序来Concat的2 SpannableString

If you're still looking for an answer, I might have a solution. I had similar problems. I used TextUtils to concat the 2 SpannableString.

下面是一些例子code:

Here is some example code:

    SpannableString span1 = new SpannableString("32m");
    SpannableString span2 = new SpannableString("50s");

    span1.setSpan(new RelativeSizeSpan(0.75f),  2, 3, 0);
    span2.setSpan(new RelativeSizeSpan(0.75f),  2, 3, 0);

    mTextView.setText(TextUtils.concat(span1," " ,span2));

这篇关于SpannableString:是否可以申请两个或两个以上RelativeSizeSpans?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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