shape的骚操作(持续更新ing)

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"关键在于这个,

猜你喜欢

转载自blog.csdn.net/z936689039/article/details/107213888
今日推荐