如何在android sqlite数据库上对齐项目

如何在android sqlite数据库上对齐项目,android,Android,我想对齐各个列标题上的项目,下面是发生的情况,是否有方法对齐该项目,或者我需要手动编写代码,谢谢 Name Hotness Yan 10 <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableRow> <

我想对齐各个列标题上的项目,下面是发生的情况,是否有方法对齐该项目,或者我需要手动编写代码,谢谢

Name                       Hotness
Yan 10   
    <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>
我的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>

如果要动态插入信息(看起来是这样),则在插入信息时必须指定行的LayoutParams。它看起来像这样

    <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>
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);

这会给你你想要的。您将确保为文本视图设置文本

在将文本视图添加到行之前,您可能需要调整文本视图的宽度和大小。您还可能需要向行中添加布局参数,这意味着您可以将“table.addView(row)”替换为“table.addView(row,l);”
    <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>