如何创建重叠图像跨度?

时间:2017-01-11 07:15:47

标签: android textview spannablestring spannable

我想创建一个SpannableString,其中包含一些情感和文字,就像这张图片一样。 enter image description here

下面是我使用过的方法,但它只是附加了文字的情感。请建议我如何创建这种类型的视图。

  private SpannableStringBuilder getLikeCountString(UserFeedData feedData, Context mContext) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        int emotionSize = (int) mContext.getResources().getDimension(R.dimen.emotion_size);
        if (feedData.getEmotionTypes() != null) {
            String[] emotions = feedData.getEmotionTypes().split(",");
            for (String emotion : emotions) {
                SpannableString emojSpan = new SpannableString("  ");
                // Getting image based on emotion id
                Drawable icon = ContextCompat.getDrawable(mContext, ContentDetailFragment.getLikeEmotionResource(Integer.valueOf(emotion.trim())));
                //icon.setBounds(0, 0, (icon.getIntrinsicWidth() / 2) + 5, (icon.getIntrinsicHeight() / 2) + 5);
                icon.setBounds(0, 0, emotionSize, emotionSize);


                ImageSpan imageSpan = new ImageSpan(icon, ImageSpan.ALIGN_BOTTOM);
                emojSpan.setSpan(imageSpan, 0, emojSpan.length() - 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                builder.append(emojSpan);

            }
        }

        if (feedData.getContentLikes() > 0) {
            builder.append(feedData.getContentLikes() + " ");
        }


        return builder;
    }

0 个答案:

没有答案