Android TableLayout 增加边框,以及圆角的实现方式

发布时间:2018-06-11作者:laosun阅读(6776)

    image.png

    android 使用tablelayout实现圆角边框布局:

    首先来看activity_main.xml的布局代码

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ebe7e4"
        android:collapseColumns="3">
    
        <TableLayout
            android:id="@+id/tablerow"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="20dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/table_shape">
    
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:text="第一行" />
            </TableRow>
    
            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:layout_margin="2dp"
                android:background="#c5c5c5" />
    
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:text="第二行" />
            </TableRow>
            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:layout_margin="2dp"
                android:background="#c5c5c5" />
    
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:text="第三行" />
            </TableRow>
        </TableLayout>
    </RelativeLayout>

    增加一个table_shape.xml,来设置边框圆角宽度等设置

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- table 背景色 -->
        <solid android:color="#fafafa"></solid>
        <!-- table 边框圆角(上下左右四个角都是圆角,如果想单独设置topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius) -->
        <corners android:radius="5dip"/>
        <!-- table 边框颜色和宽度 -->
        <stroke
            android:width="1.0dip"
            android:color="#FF0000" />
    
    </shape>


    table 表格设置边框,以及四个角进行圆角设置,都在table_shape.xml内进行。table行之间的横线使用view来进行设置即可。


4 +1

版权声明

 源码  android

 请文明留言

0 条评论