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

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

问题描述

也许这是一个愚蠢的问题,但我不能找到一种方法来inser小图像在TextView中的第二行的末尾。图像总是出现整体的TextView的权利,而不是行尾

我要插入的图像是这样的:

  TextTextTextTextTextTextTextTextTextText
TextTextTextText。 < ImageView的>
 

我所得到的是:

  TextTextTextTextTextTextTextTextTextText< ImageView的>
TextTextTextText。
 

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

源:

 < RelativeLayout的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>

        <的TextView
            机器人:ID =@ + ID /电视
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=TESTESTESTESTESTESTESTESTESTESTESTESTES
            机器人:textAppearance =机器人:ATTR / textAppearanceMedium
            机器人:文字颜色=#FFFFFF/>

        < ImageView的
            机器人:ID =@ + ID / imageView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toRightOf =@ + ID /电视
            机器人:SRC =@可绘制/图标/>
    < / RelativeLayout的>
 

解决方案

创建ImageSpan并将其添加到您的TextView。通过这种方式,你可以把你的形象,你想在文本

示例 -

  ImageSpan imagespan =新ImageSpan(appContext,的ressource);
text.setSpan(imagespan,我,我+ strLength,0); //文字的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.

I want to insert image like this:

TextTextTextTextTextTextTextTextTextText
TextTextTextText. <ImageView>

What I am getting is:

TextTextTextTextTextTextTextTextTextText  <ImageView>
TextTextTextText. 

I hope there is way to do it.

Src:

<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>

解决方案

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

Example -

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

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

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