如何向TableRow添加垂直分隔线?

时间:2016-02-24 02:48:57

标签: android

我正在尝试在课程名称和成绩之间添加一个垂直分隔符。我尝试添加一个虚拟视图并将宽度设置为1dp,但它只是扩展为占用一个单元格。我还希望以后能够根据等级对等级单元进行着色。

这是我的代码     

    <TableRow>
        <TextView
            android:layout_column="1"
            android:layout_width="21dp"
            android:ellipsize="end"
            android:id="@+id/courseName"
            android:lines="1"
            android:text="Course"
            android:breakStrategy="balanced"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:padding="3dip" />
        <TextView
            android:text="Grade"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <include
        layout="@layout/table_row"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <include
        layout="@layout/table_row"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <include
        layout="@layout/table_row"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</TableLayout>

以下是行的代码

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-1dp"
    android:paddingTop="5dp"
    android:background="@drawable/tablerow"
    tools:showIn="@layout/fragment_table">

    <TextView
        android:layout_column="1"
        android:layout_width="20dp"
        android:id="@+id/assignment_name"
        android:ellipsize="middle"
        android:lines="1"
        android:text="Course Name  loremip ipsuadfasdjfkjasldkjfm"
        android:breakStrategy="balanced"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:padding="3dip" />

    <TextView
        android:text="Grade"
        android:id="@+id/assignment_grade"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个: -

从textview中删除属性“android:layout_column =”1“”。

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

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-1dp"
            android:background="#ffaa88"
            android:weightSum="100">

            <TextView
                android:id="@+id/courseName"
                android:layout_width="0dp"
                android:layout_weight="80"
                android:breakStrategy="balanced"
                android:ellipsize="end"
                android:lines="1"
                android:padding="3dip"
                android:text="Course"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <View
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:background="#888888" />

            <TextView
                android:layout_width="0dp"
                android:layout_weight="20"
                android:gravity="right"
                android:padding="3dip"
                android:text="Grade"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <View
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:background="#FF909090" />

        <include
            layout="@layout/table_row"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <include
            layout="@layout/table_row"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <include
            layout="@layout/table_row"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </TableLayout>

table_row.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-1dp"
    android:background="#ffaa88"
    android:weightSum="100"
    tools:showIn="@layout/activity_table_layout">

    <TextView
        android:id="@+id/assignment_name"
        android:layout_width="0dp"
        android:layout_weight="80"
        android:breakStrategy="balanced"
        android:ellipsize="middle"
        android:lines="1"
        android:padding="3dip"
        android:paddingTop="5dp"
        android:text="Course Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#888888" />

    <TextView
        android:id="@+id/assignment_grade"
        android:layout_width="0dp"
        android:layout_weight="19.5"
        android:gravity="right"
        android:padding="3dip"
        android:paddingTop="5dp"
        android:text="Grade"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>