2012-09-14 36 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

相关问题