如何在多行 TextView 的末尾插入 ImageView? [英] How to insert ImageView at the end of multiline TextView?

查看:41
本文介绍了如何在多行 TextView 的末尾插入 ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个愚蠢的问题,但我找不到在 TextView 的第二行末尾插入小图像的方法.图像总是出现在整个文本视图的右侧,而不是行尾.

Maybe it's a stupid question, but I cant find a way to inser small image at the end of second line of TextView. Image is always appears to the right of whole textview, not the line end.

我想插入这样的图片:

TextTextTextTextTextTextTextTextTextText
TextTextTextText. <ImageView>

我得到的是:

TextTextTextTextTextTextTextTextTextText  <ImageView>
TextTextTextText. 

我希望有办法做到这一点.

I hope there is way to do it.

来源:

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TESTESTESTESTESTESTESTESTESTESTESTESTES"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/tv"
            android:src="@drawable/icon" />
    </RelativeLayout>

推荐答案

创建一个 ImageSpan 并将其添加到您的文本视图中.这样,您可以将图像放在文本中所需的位置

create an ImageSpan and add it to your textview. This way, you can put your image where you want in the text

示例 -

ImageSpan imagespan = new ImageSpan(appContext, ressource); 
text.setSpan(imagespan, i, i+ strLength, 0); //text is an object of TextView

这篇关于如何在多行 TextView 的末尾插入 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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