布局文件中添加以下代码:
<RelativeLayout
android:background="#222222"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/view1"
android:background="@drawable/shape_line_top"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<View
android:id="@+id/view2"
android:layout_below="@+id/view1"
android:background="@drawable/shape_line_bottom"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="1dp"/>
</RelativeLayout>
shape_line_top.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#363636"
android:startColor="#000000"
android:type="linear"
android:angle="90"/>
</shape>
shape_line_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#000000"
android:startColor="#363636"
android:type="linear"
android:angle="90"/>
</shape>
实际上就是两条渐变线组合起来的效果,shape_line_top颜色浅到深的线,shape_line_bottom由深到浅的线。