-1

I want to align the item on respective column title,here is what happen,is there a way to align this or do i need to code it manually thanks

Name                       Hotness
Yan 10   

My xml code

    <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>
4

1 回答 1

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 设置文本

于 2012-09-14T16:25:41.457 回答