如何添加图像在一个TextView文字? [英] How to add image in a TextView text?
问题描述
我是新来的Android应用程序开发和编码,我已经花了差不多我整天试图找出了这一点。
I'm new to Android app development and coding and I've spent almost my whole day trying to figure this out.
我周围中搜索在谷歌和发现这个网站,我发现与我相似的问题,其中如何将在的TextView
文字图像,例如你好,我的名字是[图]的,得到的回答是这样的:
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);
就像我说我刚刚进入Android应用程序的开发,所以我还在学习了很多,但我想知道在这个code,
Like I said I just got into Android app development so I'm still learning a lot but I would like to know in this code,
- 我该怎么打字或做的背景下?
- 我应该做一些事来了
text.setSpan()
像导入或引用,或离开它的文字?
- What am I supposed to type or do in the context?
- Am I supposed to do something to the
text.setSpan()
like import or reference or leave it text?
如果有人能打破这对我来说将是非常美联社preciated。我已经得到了这个窍门的最后2周,但我还是学到了很多东西。
If someone can break this down for me that would be much appreciated. I've been getting the hang of this for the last 2 weeks but I'm still learning a lot.
在此先感谢!
推荐答案
试试这个..
txtview.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.image, 0, 0, 0);
另请参阅该.. <一个href="http://developer.android.com/reference/android/widget/TextView.html">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:singleLine="true"
android:text="@string/name"/>
这篇关于如何添加图像在一个TextView文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!