Align bitmap in SpannableStringBuilder

会有一股神秘感。 提交于 2019-12-23 20:13:55

问题


How can I align a bitmap to the text in a SpannableString?

SpannableStringBuilder ssb = new SpannableStringBuilder(arr_messages.get(position));
String msg1 = ssb.toString();
for (int i=0; i<smileys.length; i++)
{   
        if (msg1.indexOf(smileys[i]) > 0)
        {
            int t = msg1.indexOf(smileys[i]);
            ssb.setSpan(new ImageSpan(bitmapArray.get(i)), t, t+2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
}
holder.txtName.setText(ssb, BufferType.SPANNABLE);

I would like to demonstrate the problem with these images:

What I want is to center both the text and the image vertically (the text is ok, but the image screws it up).

The result is:


回答1:


Try ...new ImageSpan(bitmapArray.get(i), ImageSpan.ALIGN_BASELINE)...!



来源:https://stackoverflow.com/questions/13751195/align-bitmap-in-spannablestringbuilder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!