下面介紹幾種簡單的方法
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"/>
效果:![]()