• Android shape记录


    之前一直觉得dataPath很好用,可以画各种矢量图。今天发现用shape画图也不错,记录一下自己用shape画的图。

    一般使用shape就是定义形状、stroke边、solid内部、corners圆角等,代码

    1. <?xml version ="1.0" encoding ="utf-8"?>
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:shape="rectangle">
    4. <corners
    5. android:radius="@dimen/dp_10" />
    6. <solid
    7. android:color="?attr/colorBgKey" />
    8. <stroke android:width="@dimen/dp_1" android:color="@color/black"/>
    9. </shape>

    然后,shape也可以处理一下复杂一点的。

    这其实是画两层,一层是一个渐变圆,一层是是个实心圆。

    shape分层就需要用到 layer-list 每一层用 item 包裹,在 item 中写具体的shape。其中item可以指定width、height、top、left、right、bottom来控制每一层的位置。

    代码如下

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    3. <item
    4. android:width="@dimen/dp_30"
    5. android:height="@dimen/dp_30">
    6. <shape android:shape="oval">
    7. <gradient
    8. android:centerX="50%"
    9. android:centerY="50%"
    10. android:endColor="#00FF0000"
    11. android:gradientRadius="50%"
    12. android:startColor="#FFFF0000"
    13. android:type="radial" />
    14. </shape>
    15. </item>
    16. <item
    17. android:width="@dimen/dp_10"
    18. android:height="@dimen/dp_10" android:top="@dimen/dp_10" android:left="@dimen/dp_10">
    19. <shape android:shape="oval">
    20. <solid android:color="#FFFF0000"/>
    21. </shape>
    22. </item>
    23. </layer-list>

    下面是一个拍照背景图片

    也是用到layer-list,代码如下

    1. <?xml version ="1.0" encoding ="utf-8"?>
    2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    3. <item>
    4. <shape android:shape="rectangle">
    5. <stroke
    6. android:width="@dimen/dp_5"
    7. android:color="?attr/colorBorder"
    8. android:dashWidth="@dimen/dp_10"
    9. android:dashGap="@dimen/dp_10" />
    10. <corners android:radius="@dimen/dp_15" />
    11. <solid android:color="?attr/colorBg" />
    12. </shape>
    13. </item>
    14. <item
    15. android:left="@dimen/dp_50"
    16. android:right="@dimen/dp_50">
    17. <shape android:shape="line">
    18. <stroke
    19. android:width="@dimen/dp_5"
    20. android:color="?attr/colorBorder" />
    21. </shape>
    22. </item>
    23. <item
    24. android:left="@dimen/dp_50"
    25. android:right="@dimen/dp_50">
    26. <rotate android:fromDegrees="90">
    27. <shape android:shape="line">
    28. <stroke
    29. android:width="@dimen/dp_5"
    30. android:color="?attr/colorBorder" />
    31. </shape>
    32. </rotate>
    33. </item>
    34. </layer-list>

  • 相关阅读:
    MTK平台Metadata的加载(4)—Q版本后
    Unirech阿里云国际版云服务器代充-使用Python批量创建实例
    GIS前端编程-地理事件动态模拟
    第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
    产品思维训练 | 小程序分类管理将有什么影响?
    XXL-JOB源码梳理——一文理清XXL-JOB实现方案
    mysql源码分析——InnoDB的内存应用整体架构源码
    Github Fork仓库的冲突与同步管理
    ISO14708-3:2017中关于有源植入物对非电离辐射的防护
    文本摘要简介
  • 原文地址:https://blog.csdn.net/Ryfall/article/details/133386563