有图又真相,先上图再说。

点击效果:

设置虚线:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="line" >
  4. <stroke
  5. android:dashGap="3dp"
  6. android:dashWidth="6dp"
  7. android:width="1dp"
  8. android:color="#63a219" />
  9. <!-- 虚线的高度 -->
  10. <size android:height="1dp" />
  11. </shape>

其中,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线

设置圆角:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle">
  4. <!-- 填充颜色 -->
  5. <solid android:color="#FFFFFF"></solid>
  6. <!-- 线的宽度,颜色灰色 -->
  7. <stroke android:width="1dp" android:color="#63a219"></stroke>
  8. <!-- 矩形的圆角半径 -->
  9. <corners android:radius="10dp" />
  10. </shape>

设置渐变填充和四个圆角半径:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:shape="rectangle">
  3. <!--分別對應上面左圆角的半径,上面右圆角的半径,下面左圆角的半径,下面右圆角的半径-->
  4. <corners
  5. android:topLeftRadius="0dp"
  6. android:topRightRadius="7dp"
  7. android:bottomLeftRadius="0dp"
  8. android:bottomRightRadius="7dp"/>
  9. <!--設置漸變-->
  10. <gradient android:startColor="#9cff00"
  11. android:endColor="#197600"
  12. android:angle="270"/>
  13. <stroke
  14. android:width="1dp"
  15. android:color="#63a219" />
  16. </shape>

设置渐变点击效果:

  1. <style name="list_item_top">
  2. <item name="android:clickable">true</item>
  3. <item name="android:focusable">true</item>
  4. <item name="android:paddingTop">10dip</item>
  5. <item name="android:paddingBottom">10dip</item>
  6. <item name="android:paddingLeft">10dip</item>
  7. <item name="android:paddingRight">10dip</item>
  8. <item name="android:gravity">center_vertical</item>
  9. <item name="android:background">@drawable/background_view_rounded_top</item>
  10. </style>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <inset xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:insetLeft="1.0px"
  4. android:insetRight="1.0px" >
  5. <selector>
  6. <item android:state_pressed="true">
  7. <shape>
  8. <gradient
  9. android:angle="270.0"
  10. android:endColor="@color/base_end_color_pressed"
  11. android:startColor="@color/base_start_color_pressed" />
  12. <corners
  13. android:bottomLeftRadius="0.0dip"
  14. android:bottomRightRadius="0.0dip"
  15. android:radius="2.0dip"
  16. android:topLeftRadius="10.0dip"
  17. android:topRightRadius="10.0dip" />
  18. <stroke
  19. android:width="1dp"
  20. android:color="#eededede" />
  21. </shape>
  22. </item>
  23. <item>
  24. <shape>
  25. <gradient
  26. android:angle="270.0"
  27. android:endColor="@color/base_end_color_default"
  28. android:startColor="@color/base_start_color_default" />
  29. <corners
  30. android:bottomLeftRadius="0.0dip"
  31. android:bottomRightRadius="0.0dip"
  32. android:radius="2.0dip"
  33. android:topLeftRadius="11.0dip"
  34. android:topRightRadius="11.0dip" />
  35. <stroke
  36. android:width="1dp"
  37. android:color="#eededede" />
  38. </shape>
  39. </item>
  40. </selector>
  41. </inset>

重新补充:好久没有关注自己的博客,没有注意到各位的评论,关于4.0以上设备虚线会变实线的问题,下面几位仁兄已经给出了答案,

代码中可以添加:

  1. line.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

xml中可以添加:

  1. android:layerType="software"

谢谢大家的参与!

源码免费下载地址:免费下载

http://download.csdn.net/detail/lan410812571/5925371

Android设置虚线、圆角、渐变的更多相关文章

  1. 【转】Android设置虚线、圆角、渐变

      Android虚线圆角渐变 有图又真相,先上图再说. 点击效果: 设置虚线: <?xml version="1.0" encoding="utf-8" ...

  2. 44.Android之Shape设置虚线、圆角和渐变学习

    Shape在Android中设定各种形状,今天记录下,由于比较简单直接贴代码. Shape子属性简单说明一下:  gradient -- 对应颜色渐变. startcolor.endcolor就不多说 ...

  3. Android 设置进度条背景

    Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...

  4. Android ActionBar标题和渐变背景

    需要在AndroidManifest.xml中设置 android:theme="@style/Theme.AppCompat" 如果提示找不到,请按下图设置: 至于如何引入的方法 ...

  5. 【转】Android开发笔记——圆角和边框们

    原文地址:http://blog.xianqu.org/2012/04/android-borders-and-radius-corners/ Android开发笔记——圆角和边框们 在做Androi ...

  6. Xamarin Android设置界面提示类型错误

    Xamarin Android设置界面提示类型错误 错误信息:Integer types not allow (at ‘padding’ with value ’10’)Android界面属性的长度和 ...

  7. 设置UIImage 圆角

    //设置UIImage圆角 @interface UIImage(UIRoundedRectImage) + (id) createRoundedRectImage:(UIImage*)image s ...

  8. 转:Android 设置屏幕不待机

    本文转载于:http://blog.csdn.net/yudajun/article/details/7748760 Android设置支部待机有两种方法 第一种简单通过设置WindowManager ...

  9. I.MX6 android 设置 默认 动态桌面

    /************************************************************************ * I.MX6 android 设置 默认 动态桌面 ...

随机推荐

  1. yum安装ftp服务器

    1.安装vsftp,本文采用yum安装: #yum install vsftpd 2.安装后运行: # service vsftpd restart Shutting downvsftpd:      ...

  2. chromedriver release note

    ----------ChromeDriver v2.25 (2016-10-25)---------- Supports Chrome v53-55 Resolved issue 1547: Chro ...

  3. 安装完 MySQL 后必须调整的 10 项配置

    原文出处: mysqlperformanceblog   译文出处:开源中国   欢迎分享原创到伯乐头条 当我们被人雇来监测MySQL性能时,人们希望我们能够检视一下MySQL配置然后给出一些提高建议 ...

  4. php多条件组合查询

    1. 通过表单把查询条件提交到php文件中,在文件中以post的形式得到传送过来的条件. 2. 把传过来的查询条件赋给变量. 3. 判断如果查询条件非空,则拼接查询sql. 大体如下: 1. < ...

  5. Django Web在Apache上的部署

    1. 安装配置Apache 2. 安装wsgi_mod模块 3. 开放相应端口 vim /etc/sysconfig/iptables # Firewall configuration written ...

  6. Fresco 多图加载之ResizeOptions

    引言 最近圈子开发工作比较重再加上寒冬已至,所以停了两个月没写,手有点生,好吧,这都是借口,我承认-( ̄▽ ̄-),下面回归正题. 一般地在使用Fresco图片的时候,无需担心图片大小的问题,因为 通常 ...

  7. KVO/KVC总结

    KVO/KVC总结       下面是根据网上文章的总结,方便查看. 在网上看别人的文章,了解KVC.KVO,有个kvo-kvc的例子,就是改变数组的内容(插入和删除),同步改变tableview中的 ...

  8. 用链表解决if语句过多的问题(C/C++实现)

    起因 http://www.cnblogs.com/code-style/p/3499408.html 设计模式的解决方案(基于python语言) http://www.cnblogs.com/cod ...

  9. cf C. Fox and Box Accumulation

    题意:输入一个n,然后输入n个数,问你可以划分多少个序列,序列为:其中一个数为c,在它的前面最多可以有c个数. 思路:先排序,然后对于每一个数逐步的找没有被用过的数,且这个数可以符合条件,然后如果没有 ...

  10. Tengine简单安装

    跟NGINX一样,没有深入研究配置,因为暂时用不到..:) 下载2.10,基于NGINX1.6.2的. 我的配置参数如下: ./configure --with-openssl=/root/tengi ...