简体   繁体   中英

android vector drawable animation is not working

As mentioned in question I'm trying to do vector drawable animation for phone icon. My requirement is to show phone animation like phone icon is moving that's it I try all suggestions from different sites,still animation is not working I am trying this from past two days still it is not happening.

Following files are my code if there is any problem please suggest me.

<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
    android:name="phone2"
    android:pathData="M 6.62 10.79 L 6.62 10.79 C 7.353 10.057 8.087 9.323 8.82 8.59 C 9.1 8.31 9.18 7.92 9.07 7.57 C 8.7 6.45 8.5 5.25 8.5 4 C 8.5 3.725 8.387 3.475 8.206 3.294 C 8.025 3.112 7.775 3 7.5 3 C 6.333 3 5.167 3 4 3 C 3.45 3 3 3.45 3 4 C 3 6.348 3.476 8.584 4.336 10.618 C 5.196 12.652 6.441 14.483 7.979 16.021 C 9.517 17.559 11.348 18.804 13.382 19.664 C 15.416 20.524 17.652 21 20 21 C 20.55 21 21 20.55 21 20 C 21 18.837 21 17.673 21 16.51 C 21 15.96 20.55 15.51 20 15.51 C 18.76 15.51 17.55 15.31 16.43 14.94 C 16.08 14.82 15.68 14.91 15.41 15.18 C 14.677 15.913 13.943 16.647 13.21 17.38 C 12.267 16.897 11.38 16.318 10.564 15.656 C 9.747 14.994 9.001 14.249 8.34 13.434 C 7.678 12.619 7.1 11.733 6.62 10.79"
    android:fillColor="#000"
    android:strokeWidth="1"/>

it is my Icon phone vector file.

    <?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:drawable="@drawable/phone2_icon"
    tools:targetApi="lollipop">
<target
    android:animation="@animator/animation_rotation"
    android:name="animation"/>
</animated-vector>

This is animated vector file.

    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="6000"
        android:propertyName="rotation"
        android:valueFrom="0"
        android:valueTo="180"
        android:valueType="floatType"/>
</set>

This is my animation file which is placed in anim folder.

If any one know anything plz help out iam first time working with vector drawables.

在此处输入图片说明

Above image is phone icon i want it is just rotate from 180 to back normal.Like it will show moving animation.

In the AnimatedVectorDrawable file you have to give "phone2" for android:name= under "target". Also against 'android:drawable="..." ' please give file name. If the name of your VectorDrawable file in "drawable" folder is "my_vector" and name of the animator file in "animator" folder is "animation_rotation" then your AnimatedVectorDrawable file should be as follows:

<animated-vector 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:drawable="@drawable/my_vector"
    tools:targetApi="lollipop">

    <target
        android:animation="@animator/animation_rotation"
        android:name="phone2"/>
</animated-vector>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM