2014-10-08 156 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