【问题标题】:How to add bitmap image to textview in android [duplicate]如何在android中将位图图像添加到textview [重复]
【发布时间】:2016-01-25 18:16:30
【问题描述】:

我有一张图片的位图。我想将该图像放在 textView 中。我怎样才能在android中做到这一点?

我检查了setCompoundDrawablesWithIntrinsicBounds(),但我只能在里面添加Drawable资源。

【问题讨论】:

  • 我不希望它作为背景图片。它应该是图片而不是文本
  • 有区别吗? textView.setText(""); 不会有前景。
  • 你应该使用ImageView 或者你有什么特殊情况可以在TextView 中设置图像吗?

标签: android


【解决方案1】:

你可以设置为textview的背景,也可以是你可以添加到textview背景中的图像。如果要在 textview 背景中添加位图,则必须转换为可绘制位图。下面是如何使用位图设置背景的代码。

TextView txt=(TextView)findViewById(R.id.textview);
txt.setBackground(new BitmapDrawable(getResources(), bitmap));

【讨论】:

    猜你喜欢
    • 2018-02-16
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多