<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="1pt" android:left="-2dp" android:right="1pt"> <!--设置除了左边都有描边-->
<shape>
<stroke android:color="@color/line_gray_e5e5e5"
android:width="1pt"/>
<corners
android:topRightRadius="30pt"
android:bottomRightRadius="30pt" />
</shape>
</item>
</layer-list>
效果图如下:这里设置了左边描边不显示
设置虚线:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <size android:height="1pt" /> <stroke android:dashGap="3pt" android:dashWidth="8pt" android:width="1pt" android:color="#e5e5e5" /> </shape>
问题:这里设置了虚线,在预览的时候显示的是虚线,但是安装到了真机里面就变成了实线。
原因:Android 3.0 之后,系统默认关闭了硬件加速功能。
解决方案:
1、view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
2、在AndroidManifest文件中,在需要用到虚线的activity的添加属性
<activity android:hardwareAccelerated="false" />
3、在xml文件的控件中设置属性layerType
android:layerType="software"
问题2:设置的虚线不显示。
原因:设置的控件的高度太小
解决方案:一般我们设置线条的高度都是1dp,改成1.5dp以上就可以显示