矢量图形介绍

android 从5.0开始支持矢量图形,Android Studio 包含一个名为 Vector Asset Studio 的工具,可帮助您添加 Material 图标以及将可扩展矢量图形 (SVG) 和 Adobe Photoshop Document (PSD) 文件作为矢量图资源导入到项目中。使用矢量图代替位图可以减小 APK 的尺寸,因为可以针对不同屏幕密度调整同一文件的大小,而不会降低图像质量。对于不支持矢量图的较早版本 Android 系统,Vector Asset Studio 可在构建时针对每种屏幕密度将矢量图转换为不同大小的位图。

Vector Asset Studio 会将矢量图形作为描述图像的 XML 文件添加到项目中。与更新多个不同分辨率的光栅图形相比,维护一个 XML 文件可能会更加轻松一些。

Android 4.4(API 级别 20)及更低版本不支持矢量图。如果最低 API 级别设置为上述 API 级别之一,则在使用 Vector Asset Studio 时您有两个选择:生成便携式网络图形 (PNG) 文件(默认)或使用支持库。

为实现向后兼容性,Vector Asset Studio 会生成矢量图的光栅图像。矢量和光栅图一起打包到 APK 中。您可以在 Java 代码中以 Drawable 的形式引用矢量图,或在 XML 代码中以@drawable 的形式引用矢量图;当您的应用运行时,对应的矢量或光栅图像会自动显示,具体取决于 API 级别。

动画支持

Google Material Design 规范提供了 Material 图标,您可以在自己的 Android 应用中使用这些图标。Vector Asset Studio 可帮助您选择、导入 Material 图标和调整其大小,以及定义不透明度和从右到左 (RTL) 的镜像设置。

Vector Asset Studio 还让您可以导入自己的 SVG 和 PSD 文件。SVG 是万维网联盟 (W3C) 制定的一个基于 XML 的开放式标准。PSD 文件格式支持 Adobe Photoshop 功能。Vector Asset Studio 支持必要的标准,但并非支持所有 SVG 和 PSD 功能。在您指定 SVG 或 PSD 文件时,Vector Asset Studio 会立即提供是否支持图形代码的反馈。它将此文件转换为包含VectorDrawable 代码的 XML 文件。如果您收到错误,应验证矢量图是否像预期一样显示。如需了解有关允许的 PSD 功能的详细信息,请参阅对 PSD 文件的支持和限制。

对于 Android 5.0(API 级别 21)及更高版本,您可以使用 AnimatedVectorDrawable 类为 VectorDrawable 类的属性添加动画。有了支持库,您可以使用 AnimatedVectorDrawableCompat 类为 Android 3.0(API 级别 11)及更高版本的 VectorDrawable 类添加动画。如需了解详细信息,请参阅 为矢量图添加动画

懒得复制了,后续暂略。

实际上图片的颜色可以通过xml的tint属性改变,只是默认是黑色的而已。

本文来自官网,参考链接

https://developer.android.com/studio/write/vector-asset-studio.html#importing

因为矢量图片的绘制使用path技术,关于paths的技术细节请参考:

https://www.w3.org/TR/SVG11/paths.html#PathData

文章中详细介绍了如何绘制这种矢量图。

主要的指令规则:

The syntax of path data is concise in order to allow for minimal file size and efficient downloads, since many SVG files will be dominated by their path data. Some of the ways that SVG attempts to minimize the size of path data are as follows:    All instructions are expressed as one character (e.g., a moveto is expressed as an M).    Superfluous white space and separators such as commas can be eliminated (e.g., "M 100 100 L 200 200" contains unnecessary spaces and could be expressed more compactly as "M100 100L200 200").    The command letter can be eliminated on subsequent commands if the same command is used multiple times in a row (e.g., you can drop the second "L" in "M 100 200 L 200 100 L -100 -200" and use "M 100 200 L 200 100 -100 -200" instead).    Relative versions of all commands are available (uppercase means absolute coordinates, lowercase means relative coordinates).    Alternate forms of lineto are available to optimize the special cases of horizontal and vertical lines (absolute and relative).    Alternate forms of curve are available to optimize the special cases where some of the control points on the current segment can be determined automatically from the control points on the previous segment.


更多相关文章

  1. Android(安卓)源码下编译APK
  2. android 项目练习:自己的词典app——生词本(二)
  3. 【转】Android自适应不同分辨率或不同屏幕大小的layout布局(横屏
  4. Android开发之旅:深入分析布局文件
  5. Android之封装好的异步网络请求框架
  6. Android加密(一)
  7. android系统图标的使用
  8. android Sqlite数据库事务处理*.sql 语句集文件
  9. Android中使用讯飞语音合成(报21001)组件未安装

随机推荐

  1. Android(安卓)自定义View 标识当前选中的
  2. android 日历开发附源码(附源码)
  3. 在Mer系统中启动Android系统(一)
  4. Android Bitmap的常用压缩方式
  5. Android开发之侧拉栏的使用
  6. Android产品研发(二十三)-->Android中保存
  7. android中关于scrollview内部组件 androi
  8. Android大图裁剪解决办法
  9. Android(安卓)studio设置requestWindowFe
  10. 学习音频之android中AudioRecord采集音频