在textview中显示位图

时间:2015-04-27 18:21:39

标签: android

我正在尝试在textview中显示位图。下面的代码使用R.drawable.bitmap_name显示textview中的位图。如何在SpannableStringBuilder中传递位图?感谢

 SpannableStringBuilder builder = new SpannableStringBuilder();
            builder.append(text).append(" ");
            builder.setSpan(new ImageSpan(MyActivity.this, R.drawable.image_1 ), builder.length() - 1, builder.length(), 0);
            myTv.setText(builder);

1 个答案:

答案 0 :(得分:2)

例如:

builder.setSpan(new ImageSpan(yourBitmap), builder.length() - 1, builder.length(), 0);

ImageSpan有以下构造函数:

new ImageSpan(Bitmap b)
new ImageSpan(Bitmap b, int verticalAlignment)
new ImageSpan(Context context, Bitmap b)
new ImageSpan(Context context, Bitmap b, int verticalAlignment)