textview末尾添加图片

private TextView content;
String showText="我是多行文字,我末尾需要添加一张图片";
//注意此处showText后+ " "主要是为了占位
  SpannableString ss = new SpannableString(showText + " ");
   int len = ss.length();
   //图片
    Drawable d = ContextCompat.getDrawable(mContext, (R.drawable.qs_more));
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    //构建ImageSpan
 ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
  ss.setSpan(span, len - 1, len, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
   content.setText(ss);

你可能感兴趣的:(textview末尾添加图片)