如何在 TextView 文本中添加图像? [英] How to add image in a TextView text?

查看:47
本文介绍了如何在 TextView 文本中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌上搜索并发现了这个网站,在那里我发现了一个类似于我的问题,其中如何在 TextView 文本中包含图像,例如 "hello my名称是 [image]",答案是这样的:

I've searched around on Google and came across this site where I found a question similar to mine in which how to include a image in a TextView text, for example "hello my name is [image]", and the answer was this:

ImageSpan is = new ImageSpan(context, resId);
text.setSpan(is, index, index + strLength, 0);

我想在这段代码中知道,

I would like to know in this code,

  1. 我应该在上下文中输入什么或做什么?
  2. 我应该对 text.setSpan() 做一些事情,比如导入或引用还是保留文本?
  1. What am I supposed to type or do in the context?
  2. Am I supposed to do something to the text.setSpan() like import or reference or leave it text?

如果有人能帮我分解一下,我将不胜感激.

If someone can break this down for me that would be much appreciated.

推荐答案

试试这个 ..

    txtview.setCompoundDrawablesWithIntrinsicBounds(
                    R.drawable.image, 0, 0, 0);

也看到这个.. http://developer.android.com/reference/android/widget/TextView.html

在xml文件中试试这个

Try this in xml file

    <TextView
        android:id="@+id/txtStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:drawableLeft="@drawable/image"
        android:drawablePadding="5dp"
        android:maxLines="1"
        android:text="@string/name"/>

这篇关于如何在 TextView 文本中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆