表格布局中的行之间的分隔

pra*_* .k 14 android tablelayout

我正在显示一个表格布局,因为我想要在表格中的行之间分隔线.也可以在表格布局中进行列方式分离.请帮助我.

以下是我的xml表格布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="6dip"
    android:paddingTop="4dip">

    <TableLayout
        android:id="@+id/tablelayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingRight="2dip">

        <TableRow>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Income"></TextView>

            <TextView
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="150dp"
                android:text="Expense"></TextView>
        </TableRow>

        <TableRow android:layout_marginTop="30px">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Household:"></TextView>

            <TextView
                android:id="@+id/text50"
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:text="Household:"></TextView>
        </TableRow>


        <TableRow android:layout_marginTop="40px">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:text="Travel:"></TextView>

            <TextView
                android:id="@+id/text51"
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-250dp"
                android:text="Travel"></TextView>
        </TableRow>

        <TableRow android:layout_marginTop="40px">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:text="Education:"></TextView>

            <TextView
                android:id="@+id/text52"
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-250dp"
                android:text="Education"></TextView>
        </TableRow>

    </TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

mai*_*inu 24

检查一下.它会工作.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:paddingBottom="6dip"
    android:paddingTop="4dip" >

    <TableLayout
        android:id="@+id/tablelayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingRight="2dip" >

        <TableRow>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Income" >
            </TextView>

            <TextView
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="150dp"
                android:text="Expense" >
            </TextView>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <View
                android:id="@+id/line1"
                android:layout_width="match_parent"
                android:layout_height="1dip"
                android:layout_weight="1"
                android:background="#FF909090"
                android:padding="2dip" />
        </TableRow>

        <TableRow android:layout_marginTop="30px" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Household:" >
            </TextView>

            <TextView
                android:id="@+id/text50"
                android:layout_width="150px"
                android:layout_height="wrap_content"
                android:text="Household:" >
            </TextView>
        </TableRow>
       </TableLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

  • 我认为这不是写作方式.如果你有20个表行,那么你必须为分隔符创建20行.....我认为在TableLayout中有一个名为"android:devider"的标签..但我不知道如何使用它...如果有些人知道请尽快告诉... (3认同)

gra*_*tnz 17

如果您只想在行之间添加分隔符,那么TableRow部门有一个很好的解决方案.

<TableLayout    
     android:divider="?android:attr/dividerHorizontal"
     android:showDividers="middle"
    ...
Run Code Online (Sandbox Code Playgroud)


ar3*_*34z 8

TableLayout扩展LinearLayout使您可以在XML中添加分隔.我认为这会起作用:

    <TableLayout
        android:id="@+id/basket_summary_table"
        android:showDividers="middle"
        android:divider="@drawable/divider_list"
        android:padding="@dimen/element_large_spacing"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="0">
    </TableLayout>
Run Code Online (Sandbox Code Playgroud)

我的分隔符如下所示:

divider_list.xml

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="1dp" />
    <solid android:color="@color/list_divider" />
</shape>
Run Code Online (Sandbox Code Playgroud)