android 斜线 绘制_Android自定义分割线

每个App都会用到分割线,一个两边顶到头的分割线只需要使用配合background属性就能够轻松实现。 常见的分割线形式还有如下这种两端或者一端留出一定空白距

每个App都会用到分割线,一个两边顶到头的分割线只需要使用配合background属性就能够轻松实现。

常见的分割线形式还有如下这种两端或者一端留出一定空白距离的分割线。

实现这种效果有很多解决方案,我能想到的有三种:

第一种,也是最简单的一种实现方式是:

android:layout_width="match_parent"

android:layout_height="@dimen/divider_height"

android:background="@android:color/white"

android:paddingLeft="@dimen/divider_padding"

android:paddingRight="@dimen/divider_padding">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/white"/>

这种实现方式会引起不必要的overdraw,因为容器的背景绘制了一次,然后分割线再绘制了一次。

第二种,可以用三个不同background的来避免overdraw

android:layout_width="match_paren