1.绘制边框时显示任意一边
比如绘制一个边框,要求底部,头部,右边没有边框,那么代码如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="-1dp"
android:top="-1dp"
android:right="-1dp">
<shape>
<stroke
android:width="1dp"
android:color="@color/gray_D9D9E9"/>
</shape>
</item>
</layer-list>
2.绘制虚线,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-600dp"
android:right="-600dp">
<rotate
android:drawable="@drawable/line_dotted_strokel"
android:fromDegrees="90"
android:visible="true" />
</item>
</layer-list>
//line_dotted_strokel:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="@color/line"
android:dashWidth="6dp"
android:dashGap="4dp" />
</shape>
然后有些机型可能只显示实线,解决方法:
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@drawable/line_dotted_vertical"
android:layerType="software"/>
android:layerType="software"关键在于这个,
3.绘制三角形
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/shape_id">
<!-- 正三角 -->
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="80%">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</rotate>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/shape_id">
<!-- 倒三角 -->
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="135%"
android:pivotY="15%"
>
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</rotate>
</item>
</layer-list>