最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android高級動畫篇之SVG矢量動畫范例

 更新時(shí)間:2021年11月11日 15:02:26   作者:FranzLiszt1847  
矢量動畫即是在計(jì)算機(jī)中使用數(shù)學(xué)方程來描述屏幕上復(fù)雜的曲線,利用圖形的抽象運(yùn)動特征來記錄變化的畫面信息的動畫,本篇帶你了解在Android中的矢量動畫

效果視頻

目錄結(jié)構(gòu)

SVG常用指令

L :為從當(dāng)前點(diǎn)繪制到直線給定的點(diǎn),后面跟著的為x,y坐標(biāo)

M :為將畫筆移動到某一點(diǎn),但只是移動畫筆,并沒有繪制過程,所有沒有產(chǎn)生繪制動作

A :為繪制一段弧線,允許弧線不閉合

初始化狀態(tài)

效果圖

制作靜態(tài)SVG圖型

首先在drawablw目錄中建立一個svg_pic.xml文件夾

分別給兩條直線名為Path1和Path2

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="200dp"
    android:height="200dp"
    android:viewportHeight="100"
    android:viewportWidth="100">

    <group>
        <path
            android:name="path1"
            android:pathData="
            M 20,80
            L 50,80 80,80"
            android:strokeColor="#cc0099"
            android:strokeLineCap="round"
            android:strokeWidth="5"/>

        <path
            android:name="path2"
            android:pathData="
            M 20,20
            L 50,20 80,20"
            android:strokeColor="#cc0099"
            android:strokeLineCap="round"
            android:strokeWidth="5"/>
    </group>

</vector>

動畫變換

在res目錄下建立一個anim文件,在anim文件建立兩個動畫變化文件,分別為cross_anim1.xml和cross_anim2.xml
其中的valueFrom與valueTo屬性分別對應(yīng)了變換的起始坐標(biāo)

cross_anim1.xml

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="sequentially">
    <objectAnimator
        android:duration="500"
        android:propertyName="pathData"
        android:valueFrom="M 20,80 L 50,80 80,80"
        android:valueTo="M 20,80 L 50,50 80,80"
        android:valueType="pathType"
        android:interpolator="@android:anim/bounce_interpolator">
    </objectAnimator>
</set>

cross_anim2.xml

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="sequentially">
    <objectAnimator
        android:duration="500"
        android:interpolator="@android:anim/bounce_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"/>
</set>

動畫黏合

最好通過animated-vector進(jìn)行粘合,在drawable目錄下創(chuàng)建link_anim.xml文件
drawable綁定svg靜態(tài)圖型的初始狀態(tài)
target將兩條直線的樣式與變換進(jìn)行綁定

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/svg_pic">
    <target android:name="path1" android:animation="@anim/cross_anim1"/>
    <target android:name="path2" android:animation="@anim/cross_anim2"/>
</animated-vector>

引用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <ImageView
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/link_anim"
        android:onClick="anim"/>
</LinearLayout>
 public void anim(View view) {
        ImageView imageView = (ImageView)view;
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof Animatable){
            ((Animatable)drawable).start();
        }
    }

解決低版本異常問題

在build.gradle文件的defaultConfig中添加如下語句

 vectorDrawables.useSupportLibrary = true

到此這篇關(guān)于Android高級動畫篇之SVG矢量動畫范例的文章就介紹到這了,更多相關(guān)Android 矢量動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

康保县| 亚东县| 兴隆县| 河间市| 江城| 郴州市| 祁门县| 绵竹市| 文登市| 洮南市| 来凤县| 金川县| 长春市| 永兴县| 双柏县| 尉犁县| 泽库县| 五台县| 岢岚县| 宣威市| 北流市| 荣昌县| 商都县| 贡山| 依兰县| 大悟县| 阿拉善盟| 郯城县| 师宗县| 昆山市| 洮南市| 开封市| 新化县| 凌海市| 来宾市| 简阳市| 莆田市| 永年县| 承德市| 乡城县| 莱阳市|