2014-10-08 168 views
0

我创建了一个包含某些单独标题信息的表。但是,我想知道如何将静态图像输入到列中的单个单元格中。如何将图像添加到TextView中

TextView label_col_1_datatab3 = new TextView(this); 
label_col_1_datatab3.setId(200+cnt); 
label_col_1_datatab3.addTouchables(chair_list +count); //THERE IS AN ERROR FOR THIS LINE WHERE I AM TRYING TO INPUT AN ARRAY OF IMAGES. 
label_col_1_datatab3.setText(product_showcase_list[cnt]); 
label_col_1_datatab3.setTextColor(Color.BLACK); 
label_col_1_datatab3.setPadding(100, 50, 100, 50); 
row_tab3.addView(label_col_1_datatab3); 

代码chair_list:

ArrayList<View> chair_list = new ArrayList { 

     R.drawable.banana_chair, 
     R.drawable.circular_chair, 
     R.drawable.purplechair 
}; 

XML:

   <TableRow 
       android:id="@+id/table_Row1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
           <ListView 
            android:id="@+id/list_image" 
            android:layout_width="80dip" 
            android:layout_height="80dip" 
            android:src="@drawable/banana_chair"/> 
           <ListView 
            android:id="@+id/list_image2" 
            android:layout_width="80dip" 
            android:layout_height="80dip" 
            android:src="@drawable/circular_chair"/> 
           <ListView 
            android:id="@+id/list_image3" 
            android:layout_width="80dip" 
            android:layout_height="80dip" 
            android:src="@drawable/purplechair"/> 
      </TableRow> 
+0

在XML文本视图中试试drawableright或drawabletop或drawableleft或drawableleft? – Dhina 2014-10-08 09:25:16

+0

@Dina你是什么意思?我更新了XML代码 – 2014-10-08 09:43:04

回答

2

尝试用于创建特定的列,它是包容在每个单元中的图像

代码下面的代码片段:

TextView label_col_1_datatab3 = new TextView(this); 
label_col_1_datatab3 .setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0); 
+0

,但该参数仅适用于一个可绘制的图标?如果我有多个? – 2014-10-08 09:46:23

+0

@ErnestLee只能绘制一个绘图,可以在文本的末尾,左侧,右侧/开始/之上绘制。检查:http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) – Abdellah 2014-10-08 09:53:41

+0

理解,但如果我需要在不同的单元格中添加不同的图像怎么样? – 2014-10-08 09:59:19