在Lollipop设备中输入活动时,AnimatedVectorDrawable有时有时不动画

时间:2019-01-30 14:20:31

标签: android android-animation android-drawable vector-graphics android-vectordrawable

我正在尝试使用AnimatedVectorDrawable实现圆形加载器类型的动画

这是我AnimatedVectorDrawable的XML代码:

vector_example.xml

<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="64dp"
        android:height="64dp"
        android:viewportWidth="600"
        android:viewportHeight="600">
        <group
            android:name="rotationGroup"
            android:pivotX="300"
            android:pivotY="300"
            android:rotation="45.0" >
            <path
                android:name="vectorPath"
                android:fillColor="@color/colorPrimary"
                android:pathData="some path data" />
        </group>

        <!--<group-->
            <!--android:name="stationaryGroup">-->
            <!--<path-->
                <!--android:name="somePath"-->
                <!--android:fillColor="#FFEFEFEF"-->
                <!--android:pathData="some path data"/>-->
        <!--</group>-->
    </vector>
</aapt:attr>
<target android:name="rotationGroup">
    <aapt:attr name="android:animation">
        <objectAnimator
            android:propertyName="rotation"
            android:valueFrom="0"
            android:valueTo="360"
            android:repeatCount="infinite"
            android:duration="1000"
            android:interpolator="@android:interpolator/linear" />
    </aapt:attr>
</target>
</animated-vector>

我面临的问题是,在我的较新设备中,它运行正常,但是在我的Lollipop设备中,当我进入活动时,它有时会冻结并且根本不动。当我反复重新进入活动时,动画看起来好像已经进步了一点,但仍然静止不动。偶尔会正常工作。

其他相关代码:

活动

 final ImageView imageView2 = findViewById(R.id.sampleview);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        final AnimatedVectorDrawable e = (AnimatedVectorDrawable) getDrawable(R.drawable.vector_example);
        imageView2.setImageDrawable(e);
        e.start();
    } 

build.gradle

vectorDrawables.useSupportLibrary = true

参考:

AnimatedVectorDrawable does not animate-我已经做到了

0 个答案:

没有答案
相关问题