首页 > 学院 > 开发设计 > 正文

利用shape画虚线

2019-11-06 09:55:52
字体:
来源:转载
供稿:网友

在drawable目录下新建bg_dash_line.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="3px" android:color="#FFFFFF" android:dashWidth="10px" android:dashGap="10px" /></shape>

说明: 显示一条虚线,width为线条的高度,dashWidth为破折线的宽度,dashGap为破折线之间的空隙的宽度,当dashGap=0时,就是实线 注意: **1. 如果在标签中设置了android:width,则在标签中android:layout_height的值必须大于android:width的值,否则虚线不会显示。如果不设置,默认android:width为0。 2. 关于4.0以上设备虚线会变实线的问题:** 代码中可以添加:

line.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

XML中可以添加:

android:layerType="software"

如上例所示,如果想正常的显示虚线:

<View android:layout_width="match_parent" android:layout_height="4px" android:layerType="software" android:background="@drawable/bg_dash_line"/>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表