【问题标题】:how to add vertical and horizontal divider in table layout?如何在表格布局中添加垂直和水平分隔线?
【发布时间】:2019-05-10 10:55:13
【问题描述】:

我正在尝试创建一个屏幕,以表格格式显示学生及其在不同科目中的相应分数。如何创建垂直和水平分隔线?

【问题讨论】:

    标签: android tablelayout


    【解决方案1】:

    您正在寻找如何围绕表格行和表格布局创建边框。而不是分频器。 您必须创建一个可绘制对象作为边框,然后将其设置为背景。 她的解决方案:

    res/drawable/shape_table.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape= "rectangle">
       <solid android:color="#000000"/>
       <stroke android:width="1dp" android:color="#000000"/>
    </shape>
    

    您的 Layout.xml

    <TableLayout
         ....>
         <TableRow
             ....
              android:background="@drawable/shape_table">
    
               <TextView
                ...
                  android:background="@drawable/shape_table"
                  />
    
               <TextView
                ...
                  android:background="@drawable/shape_border"
                   />
         </TableRow>
    </TableLayout>  
    

    如果您正在寻找一个分隔线,您可以使用 垂直:

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0"/>
    

    水平:

    <View
            android:layout_width="2dp"
            android:layout_height="match_parent"
            android:background="#c0c0c0"/>
    

    【讨论】:

      【解决方案2】:

      在每行项目之后使用此代码

      XML 中的水平线

      <View android:layout_width="match_parent"
        android:background="@android:color/red" 
        android:layout_height="2dp" />
      

      XML 中的垂直线

      <View android:layout_width="2dp"
        android:background="@android:color/red" 
        android:layout_height="match_parent"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-13
        • 2013-05-13
        • 2014-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-27
        相关资源
        最近更新 更多