textview中的图像

时间:2012-07-30 13:12:19

标签: android textview

在我的应用程序中,我在列表视图中显示数据库中的数据。在列表视图中,我有4个textwise视图。现在在第二个textview之后,我必须添加1个图像(星号)来表示某些东西。但是当我试图添加所有的文本视图远远落后于屏幕时,不影响其他textview我有表明这一点。

我的展示:

30/07/2012 | gfgdh | 78 | 78
30/07/2012 | hjkk  | 45 | 45

我想要的是:

30/07/2012 | ghgdh* |78  |78

我的Xml代码是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/Layout1"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     >     

     <TextView android:id="@+id/text1"      
        android:layout_width="80dip"
        android:layout_height="wrap_content"        
        /> 

     <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:background="#FF909090" />

     <TextView android:id="@+id/text3"          
        android:layout_width="60dip"
        android:layout_height="wrap_content"        
        android:layout_marginLeft="30dp"/>


     <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:background="#FF909090" />

       <TextView android:id="@+id/text5"            
        android:layout_width="60dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        />
       <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:background="#FF909090" />

        <TextView android:id="@+id/text7"           
        android:layout_width="60dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        />

          <TextView android:id="@+id/text9"         
        android:layout_width="60dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"            
         android:visibility="gone"/>


</LinearLayout>

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以创建spannableString并将图像放在TextView中所需的位置。或者你可以使用

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

Source