如何在多行的TextView的末尾插入ImageView的?末尾、如何在、TextView、ImageView

由网友(冇心)分享简介:也许这是一个愚蠢的问题,但我不能找到一种方法来inser小图像在TextView中的第二行的末尾。图像总是出现整体的TextView的权利,而不是行尾我要插入的图像是这样的:TextTextTextTextTextTextTextTextTextTextTextTextTextText。 < 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的>
 
word中显示的 节的结尾 是怎么插入的呢

解决方案

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

阅读全文

相关推荐

最新文章