1.自定义View画线
下面介绍几种简单的方法
2.textView和View画直线
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#bfbfbf" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF909090"/>
background为设置直线的颜色
但是也只能画直线
3.自定义shape文件
dotted_line.xml文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="3dp"
android:dashWidth="6dp"
android:width="1dp"
android:color="#bfbfbf" />
<!-- 虚线的高度 -->
<size android:height="1dp" />
</shape>
其中,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线在你的xml布局中引用
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/dotted_line"
android:layerType="software"/>
效果: