我们知道,想在Android XML中画出一条直线,很简单:

<View     android:layout_width="match_parent"     android:layout_height="1px"     android:background="#FFFFFF"/>

  如果想要画出一条虚线呢?  

在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. 如果在<stroke>标签中设置了android:width,则在<View>标签中android:layout_height的值必须大于android:width的值,否则虚线不会显示。如果不设置,默认android:width为0。

2.关于4.0以上设备虚线会变实线的问题:

代码中可以添加:

[java]view plaincopy
  1. line.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
XML中可以添加:

[html]view plaincopy
  1. android:layerType="software"

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

<View     android:layout_width="match_parent"     android:layout_height="4px"     android:layerType="software"     android:background="@drawable/bg_dash_line"/>


更多相关文章

  1. Android实现天气预报温度/气温折线趋势图
  2. android画一条虚线
  3. Android时间倒计时的简单实线
  4. android 绘制折线图(AChartEngine)Linechart静态的
  5. Android之玩转MPAndroidChart让(折线图、柱形图、饼状图、散列图
  6. Android绘制简单折线图的步骤
  7. android使用xml实现虚线效果
  8. 自定义控件--虚线
  9. Android:res之shape制作圆角、虚线、渐变

随机推荐

  1. Sql Server 2000 行转列的实现(横排)
  2. 一个分页存储过程代码
  3. 文本、Excel、Access数据导入SQL Server2
  4. 列出SQL Server中具有默认值的所有字段的
  5. 阿拉伯数字转大写中文_财务常用sql存储过
  6. SQL Server存储过程的基础说明
  7. 在 SQLSERVER 中快速有条件删除海量数据
  8. 在SQL Server启动时自动执行存储过程。第
  9. sqlserver只有MDF文件恢复数据库的方法
  10. sqlserver 游标的简单示例