形状Drawable

作者:追风剑情 发布于:2016-7-27 16:51 分类:Android

线

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="line">
  4. <!-- 引用虚线的view需要添加属性android:layerType,值设为"software",否则显示不了虚线。 -->
  5. <!-- 定义线条颜色和粗细 -->
  6. <stroke
  7. android:width="2dp"
  8. android:color="#ffff00"
  9. android:dashWidth="4dp"
  10. android:dashGap="4dp"/>
  11. <size android:height="40dp" />
  12. </shape>

矩形

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle">
  4. <solid android:color="#2F90BD"/>
  5. <!-- 定义虚线轮廓线 -->
  6. <stroke
  7. android:width="2dp"
  8. android:color="#00ff00"
  9. android:dashWidth="20dp"
  10. android:dashGap="4dp"
  11. />
  12. <!-- 定义圆角 -->
  13. <corners android:radius="15dp"/>
  14. <!-- 定义内补丁 -->
  15. <padding
  16. android:left="10dp"
  17. android:top="10dp"
  18. android:right="10dp"
  19. android:bottom="10dp"
  20. />
  21. </shape>

椭圆

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="oval" >
  4. <!-- 定义椭圆颜色 -->
  5. <solid android:color="#2F90BD"/>
  6. <!-- 定义虚线轮廓线 -->
  7. <stroke
  8. android:width="2dp"
  9. android:color="#00ff00"
  10. android:dashWidth="4dp"
  11. android:dashGap="4dp"
  12. />
  13. <!-- padding设置内间距 -->
  14. <padding
  15. android:bottom="4dp"
  16. android:left="4dp"
  17. android:right="4dp"
  18. android:top="4dp" />
  19. <!-- size设置形状的大小 -->
  20. <size
  21. android:width="60dp"
  22. android:height="40dp" />
  23. </shape>

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="ring"
  4. android:innerRadiusRatio="3"
  5. android:thicknessRatio="9"
  6. android:useLevel="false" >
  7. <!-- 环的厚度=环的直径/thicknessRatio -->
  8. <!-- 内环半径=环的直径/innerRadiusRatio -->
  9. <!-- 定义颜色 -->
  10. <solid android:color="#2F90BD"/>
  11. <!-- 定义轮廓线 -->
  12. <stroke
  13. android:width="1dp"
  14. android:color="#ffffff"
  15. />
  16. <!-- 定义渐变 -->
  17. <gradient
  18. android:endColor="#2F90BD"
  19. android:startColor="#FFFFFF"
  20. android:type="sweep" />
  21. </shape>

运行测试

111111.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号