2012-09-14 83 views
-1

的項目我要對齊的相應列標題的項目,這裏是發生什麼事,有沒有辦法來排列這還是我需要編寫它手動感謝如何使Android上的SQLite數據庫

Name      Hotness 
Yan 10 

我的XML代碼

<TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <TableRow> 

      <TextView 
       android:layout_width="fill_parent" //this is my column 1 which Name 
       android:layout_weight="1" 
       android:layout_height="fill_parent" 
       android:text="Names" > 
      </TextView> 

      <TextView 

       android:layout_width="fill_parent"  //the column 2 which is Hotness 
        android:layout_weight="1" 
       android:layout_height="fill_parent" 
       android:text="Hotness" > 
      </TextView> 
     </TableRow> 
     </TableLayout> 

     <TextView 
      android:id="@+id/tvSqlInfo"  //to save on the database 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:layout_height="fill_parent" 
      android:text="get info" > 
     </TextView> 


</LinearLayout> 

回答

2

如果要插入動態信息,它看起來,你是,你將不得不當你插入到指定行的LayoutParams。它看起來像這樣

TableLayout table = (TableLayout) findViewById(SOME_ID_THAT_YOU_ASSIGN_TO_YOU_LAYOUT) 
TableRow row = new TableRow(this); 
TextView text = new TextView(this); 
TableLayout.LayoutParams l = 
      new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
l.weight = 1; 
row.addView(text); 
table.addView(row); 

這應該給你你想要的。你將確保你設置textView的文本

+0

我試過你的例子,但它仍然沒有對齊 – user1590096

+0

你可能將不得不使用textviews的寬度和大小,然後再將它們添加到你的行中。你也可能需要向行添加布局參數,這意味着你可以用「table.addView(row,l);」替換「table.addView(row)」。 – zabawaba99

相關問題