美文网首页
9.SVG动画

9.SVG动画

作者: Varmin | 来源:发表于2017-05-30 23:48 被阅读0次

SVG:

资料1
资料2

用法:

  • VectorDrawable: 创建基于XML的SVG图形
  • AnimatedVectorDrawable:"胶水",实现动画
  • 语法什么的看资料。
创建vector SVG文件:
  • 通过下面xml文件,根据语法画: VectorDrawable
  • 网站SVG图片源码/Studio--> new--> vector Asset/ps,AI将图片转换成SVG
//res/drawable目录
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="200dp"
    android:height="200dp"
    android:viewportHeight="100"
    android:viewportWidth="100">
    <group>
        <!-- 如果指定属性为 pathData,
             则要添加一个属性 android:strokeLineCap="pathType",来告诉系统进行pathData变换-->

        <path
            android:name="path1"
            android:pathData="
            M 20,20
            L 50,20 80,20"
            android:strokeColor="#000"
            android:strokeLineCap="round"
            android:strokeWidth="5" />
        <path
            android:name="path2"
            android:pathData="
            M 20,80
            L 50,80 80,80"
            android:strokeColor="#000"
            android:strokeLineCap="round"
            android:strokeWidth="5" />
        //中间的线,自己加上去的。    
        <path
            android:name="path3"
            android:pathData="
            M 20,50
            L 45,50 M 55,50  80,50"
            android:strokeColor="#000"
            android:strokeLineCap="round"
            android:strokeWidth="5" />
    </group>
</vector>

创建animator:

// res/animtor目录
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:interpolator="@android:anim/linear_interpolator"
    android:propertyName="pathData"
    android:valueFrom="M 20,20 L 50,20 80,20"
    android:valueTo="M 20,20 L 50,50 80,20"
    android:valueType="pathType"/>

创建 animated-vector文件:

  • "胶水" 把 VectorDrawable 和 objectAnimator 连起来。
//  res/drawable目录
<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    //引入vector
    android:drawable="@drawable/svg_lines">
    <target
        //此处的name必须和vector中的name一致,才能知道动画要作用到哪个path
        android:name="path1"
        //动画
        android:animation="@animator/obj_svg_path_1">
    </target>
    <target
        android:name="path2"
        android:animation="@animator/obj_svg_path_2">
    </target>
</animated-vector>

开始动画:

// xml中设置backgroud,代码中用getBackground();
// xml中设置src属性,代码中用getDrawable();
// Animatable animDrawable = (Animatable)ivSvgTarget.getBackground();
Animatable animDrawable = (Animatable) ivSvgTarget.getDrawable();
if (!animDrawable.isRunning()) {
    animDrawable.start();
    }

相关文章

  • 9.SVG动画

    SVG: 资料1资料2 用法: VectorDrawable: 创建基于XML的SVG图形 AnimatedVec...

  • 9.svg 动画 相关文章

    超级强大的SVG SMIL animation动画详解;深度掌握SVG路径path的贝塞尔曲线指令 2.拿来就能用...

  • Android回顾--(十六) 动画简析

    动画: 补间动画(Tween动画) 帧动画(Frame动画) 属性动画(Property动画) 补间动画 特点: ...

  • 在山西太原,做个二维动画需要哪些制作流程?

    二维动画有哪些类型? flash动画,课件动画,mg动画,ae动画,GIF动画,手绘动画,网页动画,企业动画,宣传...

  • Android 动画

    【Android 动画】 动画分类补间动画(Tween动画)帧动画(Frame 动画)属性动画(Property ...

  • 动画学习

    动画 分为 组动画,属性动画,渐变动画,其中属性动画包括 普通动画和关键帧动画,其他动弹动画,动画层分为 pres...

  • Android动画

    Android动画分类: 视图动画:补间动画、逐帧动画 属性动画 视图动画 补间动画 可以在xml中定义动画,然后...

  • iOS动画

    iOS动画-从UIView动画说起iOS动画-Transform和KeyFrame动画iOS动画-layout动画...

  • Android动画之视图动画

    分类 Android动画主要包括视图动画和属性动画。视图动画包括Tween动画和Frame动画。Tween动画又包...

  • Android 动画

    android动画分为三种 帧动画,视图动画(补间动画),属性动画逐帧动画 视图动画 属性动画 Window和A...

网友评论

      本文标题:9.SVG动画

      本文链接:https://www.haomeiwen.com/subject/uvldfxtx.html