在spannablestring中的文本上方的笑脸

时间:2014-08-25 09:33:10

标签: android spannablestring

我使用以下代码添加图像范围。

Drawable happySmiley = ctx.getResources().getDrawable(
     R.drawable.img_smile);
     happySmiley.setBounds(0, 0, happySmiley.getIntrinsicWidth(),
     happySmiley.getIntrinsicHeight());

     Drawable sadSmiley = ctx.getResources()
     .getDrawable(R.drawable.ic_launcher);
     sadSmiley
     .setBounds(0, 0, sadSmiley.getIntrinsicWidth(),
     sadSmiley.getIntrinsicHeight());

     SpannableStringBuilder builder = new SpannableStringBuilder();
     builder.append("Some text ");
     builder.setSpan(new ImageSpan(happySmiley), builder.length()-1, builder.length(),
     Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

     builder.append(". More text [sad_smiley_anchor]");
     builder.setSpan(new ImageSpan(sadSmiley), builder.length()
     - "[sad_smiley_anchor]".length(), builder.length(),
     Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

     tvSS.setText(builder);


o/p Some text (smiley). More text (smiley).

But I want to display the smiley above the "Some" in "Some text". Like

(Smiley)    (Smiley)
Some Text. More text.

如果可以将笑脸设置为“Some some”中的“Some”的背景,例如setForegroundSpan()等,那么问题也可能会缩短。请对此发表评论。

Thanks

0 个答案:

没有答案