使用环境:
偶尔会用到,一根虚线………………
使用方法:
小技巧讲述: view的height一定要比shape中line的height高! 第二,shape中要有<size height = 1dp>
上代码:
<?xml version="1.0" encoding="utf-8"?> <View xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/two" android:background="@drawable/dashfive" android:layerType="software" />
dashfive/drawablw
<?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="#999999" android:dashGap="5dp" android:dashWidth="5dp" /> <size android:height="@dimen/one"/> </shape>至于xml文件是怎么写的,平时一根线怎么写就怎么写,但是要加一条属性:
android:layerType="software"
出来的效果是:
亲测,AS版本3.0,Android版本5.1,管用!
实现虚线分割线
本文介绍如何在Android中实现自定义虚线分割线的方法。通过调整View的高度和使用特定的shape属性,可以创建出高度仅为1dp的虚线。文中提供了具体的XML代码示例,并强调了确保View的高度大于shape中线的高度的重要性。
4041

被折叠的 条评论
为什么被折叠?



