发布时间:2018-06-11作者:laosun阅读(6351)
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来进行设置即可。
版权属于: 技术客
原文地址: https://www.sunjs.com/article/detail/fe182a39b1ac4acb98b8fffc2cd22e37.html
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。