vector drawable
来源:互联网 发布:神反转的故事知乎 编辑:程序博客网 时间:2024/06/15 04:14
AnimatedVectorDrawable
vector drawable 类似于网页设计的SVG是一种可缩放的矢量图,要是能用的话尽量用这种格式的图片,特别是一些图标。例如:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
vector drawable 形状由pathData决定,修改pathData就能修改vector drawable的形状。
VectorDrawable官方文档
关于vector drawable的兼容和一些问题,推荐看Android Vector曲折的兼容之路这篇博客。
VectorDrawable 的标签中有几个很重要:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
关于path中的pathData,参照SVG中定义的path标签的中的命令的定义。
Path中的命令详解
- 指令
- M = moveto (M X,Y) : 将画笔移动到指定的坐标位置
- L = lineto (L X, Y) : 画直线到指定的坐标位置
- H = horizontal lineto (H X) : 画水平线到指定的坐标
- V = vertical lineto (V Y) : 画垂直线到指定的坐标
- C = curveto (C X1, Y1, X2, Y2, ENDX, ENDY) : 三次贝塞尔曲线
- S = smooth curveto (S X2, Y2, ENDX, ENDY)
- Q = quadratic Belzier curveto (Q X, Y, ENDX, ENDY) : 二次贝塞尔曲线
- T = smooth quadratic Belzier curveto (T ENDX, ENDY) : 映射
- A = elliptical Arc(A RX,RY,XROTATION,FLAG_LARGE, FLAG_SWEEP, X, Y) :画弧线。
- Z = closepath (z) : 关闭路径。
- 使用的原则
- 坐标轴为(0,0)为中心,X轴水平向右,Y轴水平
- 所有指令大小写区分,大写采用绝对定位,参照全局的坐标系,小写采用相对定位,参照父坐标系(上一次绘制停留的那个位置)
- 指令和数据之间的空格可以省略
- 同一指令出现多次可以只用一个。
对vector drawable 进行动画,可以进行下面这些动画,最重要的是最后三点:
- translate 平移
- scale 缩放
- rotate 旋转
- opacity 透明度修改
- color 色彩修改 (android:stokeColor ,android:fillColor)
- path 路径改变
- trim start/end (android:trimPathStart / android:trimPathEnd)路径剪裁
- clip-path 剪切路径
vector drawable的原理也只是使用属性动画,查看其源码,上述的属性都能找到对应的setter和getter函数,所有能进行这些动画。
路径变化动画 : 例如我们将一个符号”√”变换成一个”x”符号。
创建两个vector drawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
创建属性动画
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
创建AnimatedVectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 使用AnimatedVectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
注意:要想对pathData进行改变,这个两个pathData中的命令必须是一样的,只是参数不一样而已,否则会报错误的。
cross为: M 6.4,6.4 L 17.6,17.6 M 6.4,17.6 L 17.6,6.4
tick 为:M 4.8,13.4 L 9,17.6 M 10.4,16.2 L 19.6,7
两者都分别采用了:M, L, M,L 四个命令,只是参数不一样而已,故两者之间可以进行改变。path 绘制动态效果,例如显示”Android Design“这两个单词使其看起来像在书写出来一样。这里使用到的关键点就是path的android:trimPathEnd属性。
将”Android Design”拆成多个路径再定义vector drawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
定义每个path所需要用到的动画
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
创建AnimatedVectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
使用AnimatedVectorDrawerable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
clip-path 实现填充或者镂空。
主要使用到的是clip-path这个标签。这个标签对当前group和child group 有效。而且,定义clip-path后,知会对clip-path后面的path产生效果。而不会对clip-path前产生效果。例如:定义vectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
这个例子中的clip-path值对empty这个path有效,而无法影响full这个path。
定义需要用到的动画
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
定义AnimatedVectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 代码中使用AnimatedVectorDrawable
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
制作vector
先制作svg,再将svg转换成android的vector drawable.
1. 在线制作svg,
2. 在线svg转换为vector
- vector drawable
- Vector Drawable、Animated Vector Drawable
- 初识android vector drawable
- Vector Drawable 使用
- Android:Vector Drawable 使用
- Android Vector Drawable | SVG 矢量图
- android 中vector drawable使用
- Android中的矢量图Vector Drawable
- android invalid drawable tag vector解决办法
- Android Drawable Mipmap Vector使用及Vector兼容
- 用vector drawable加快应用图片加载速度
- Rendering Problems invalid drawable tag vector android studio 显示问题
- 动画和图形:画布和可绘制对象:Vector Drawable
- Android invalid drawable tag vector错误的解决办法
- Drawable
- Drawable
- Drawable
- Drawable
- 我对printf函数的一些理解
- 还是畅通工程(Kruskal)
- C 知识点(5)
- Territorial Dispute
- 非监督特征学习与深度学习(十二)---- 卷积神经网络
- vector drawable
- Python回顾
- MySQL LIKE 子句
- elipse快捷键
- 深入理解SELinux SEAndroid
- 推箱子
- A+B Problem
- Python学习 (1)从IDLE启动Python
- set集合遍历方法