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


点击效果:




设置虚线:

[html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <shapexmlns: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. <sizeandroid:height="1dp"/>
  11. </shape>

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


设置圆角:

[html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle">
  4. <!--填充颜色-->
  5. <solidandroid:color="#FFFFFF"></solid>
  6. <!--线的宽度,颜色灰色-->
  7. <strokeandroid:width="1dp"android:color="#63a219"></stroke>
  8. <!--矩形的圆角半径-->
  9. <cornersandroid:radius="10dp"/>
  10. </shape>

设置渐变填充和四个圆角半径:
[html] view plain copy
  1. <shapexmlns: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. <gradientandroid:startColor="#9cff00"
  11. android:endColor="#197600"
  12. android:angle="270"/>
  13. <stroke
  14. android:width="1dp"
  15. android:color="#63a219"/>
  16. </shape>


设置渐变点击效果:

[html] view plain copy
  1. <stylename="list_item_top">
  2. <itemname="android:clickable">true</item>
  3. <itemname="android:focusable">true</item>
  4. <itemname="android:paddingTop">10dip</item>
  5. <itemname="android:paddingBottom">10dip</item>
  6. <itemname="android:paddingLeft">10dip</item>
  7. <itemname="android:paddingRight">10dip</item>
  8. <itemname="android:gravity">center_vertical</item>
  9. <itemname="android:background">@drawable/background_view_rounded_top</item>
  10. </style>

[html] view plain copy
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <insetxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:insetLeft="1.0px"
  4. android:insetRight="1.0px">
  5. <selector>
  6. <itemandroid: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以上设备虚线会变实线的问题,下面几位仁兄已经给出了答案,

代码中可以添加:

[java] view plain copy
  1. line.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

xml中可以添加:

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

谢谢大家的参与!


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

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

更多相关文章

  1. Android(安卓)Studio中使用simpleUML绘制类图详细使用及说明
  2. Drawable的详解
  3. Android(安卓)Paint之MaskFilter详解
  4. Android(安卓)实现对话框圆角功能
  5. Android(安卓)UI效果实现——滑动模糊渐变效果实现
  6. Android实现虚线的方法
  7. Android(安卓)中shape的使用(圆角矩形)
  8. 32、详解Android(安卓)shape的使用方法
  9. Android中shape详解

随机推荐

  1. PHP多线程编程
  2. 使用AJAX将数据发送到.php文件,如何从中获
  3. 解决PHP导出大量数据时设置超链接的问题
  4. 为什么我们坚持选择用php
  5. PHP结合Redis来限制用户或者IP某个时间段
  6. PHP替换标签字符
  7. 单击保存按钮(PHP和MSQL)时如何保存记录列
  8. 根据网址上的国家/地区将用户重定向到正
  9. 今天开始学php,第一次写博客以鼓励自己能
  10. smarty模板引擎变量的传递方法