type
status
date
slug
summary
tags
category
password
icon

绘制的基本要素:

  • 重写 onDraw()
  • 使⽤ Canvas 来绘制
  • 使⽤ Paint 来配置
  • 坐标系(旋转的正向为顺时针)
    • notion image
  • 尺⼨单位是像素,⽽不是 dp。转换⽅式:

    Path 的⽅向以及封闭图形的内外判断:

    • Winding: 如果⽅向相反的穿插次数相等则为外部,不等则为内部:
      • 单圆:
        • notion image
      • 双圆同向:
        • notion image
      • 双圆不同向:
        • notion image
    • Even Odd:不考虑⽅向。穿插奇数次则为内部,偶数次则为外部:
      • 单圆:
        • notion image
      • 双圆:
        • notion image
     

    PathMeasure

    把 Path 对象填⼊,⽤于对 Path 做针对性的计算(例如图形周⻓)。

    仪表盘

    • ⽤ drawArc() 绘制弧形
    • 三⻆函数的计算:横向的位移是 cos,纵向的位移是 sin
    • PathDashPathEffect
      • 加上 PathEffect 之后,就只绘制 effect,⽽不绘制原图形。所以需要弧线和刻度分别绘制,⼀共两次。
      • dash 的⽅向
        • 绘制 dash 的轨迹是这样的:
          • notion image
        • ⽽由于 x 轴的正向是轨迹的正向(这是规定),所以实际上的物理模型是这样的:
          • notion image
        • 那么,如果你要加上刻度,就应该这样设置:
          • notion image
        • 然后,你的刻度就会沿着轨迹绘制:
          • notion image
        • advance 计算
          • notion image
     

    饼图

    • ⽤ drawArc() 绘制扇形
    • ⽤ Canvas.translate() 来移动扇形,并⽤ Canvas.save() 和 Canvas.restore() 来保存和恢复位置
    • ⽤三⻆函数 cos 和 sin 来计算偏移
      • notion image
    范围裁切和⼏何变换从 OkHttp 的原理来看 HTTP
    Loading...
    shuouyang
    shuouyang
    android开发 ReactNative开发 小程序开发
    最新发布
    AOSP 环境搭建
    2025-3-29
    View 绘制流程-源码解析
    2025-3-12
    HTTP
    2025-3-4
    JVM 虚拟机
    2025-2-28
    蓝牙-BLE-基础
    2025-2-28
    从 OkHttp 的原理来看 HTTP
    2025-2-19
    公告
    🎉热点信息🎉
    --- 1 ---
    Jet Brains 推出新的跨平台支持 Kotlin MultiPlatform
    --- 2 ---
    新的小巧便捷的依赖注入框架 Koin
    --- 3 ---
    新一代 API 查询语言 GraphQL