Animated Vector Drawable无法与API 15一起使用 [英] Animated Vector Drawable not working with API 15

查看:61
本文介绍了Animated Vector Drawable无法与API 15一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在API级别为15的设备上运行Drawable动画。

I've been trying to run an Animated Vector Drawable on a device with API level 15.

以下是我的动画矢量 animated_feedback.xml:

The following is my animated vector "animated_feedback.xml":

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 android:drawable="@drawable/feedback">

    <target
    android:animation="@animator/background_circle_animator"
    android:name="BG_White_Circle"/>

</animated-vector>

可绘制的 feedback.xml包含以下内容:

The drawable "feedback.xml" contains the following:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="180dp"
        android:height="180dp"
        android:viewportWidth="180"
        android:viewportHeight="180">
    <group
        android:name="BG_White_Circle_Group">
        <path
            android:name="BG_White_Circle"
            android:fillColor="#fff"
            android:pathData="M 90 0 C 139.705627485 0 180 40.2943725152 180 90 C 180 139.705627485 139.705627485 180 90 180 C 40.2943725152 180 0 139.705627485 0 90 C 0 40.2943725152 40.2943725152 0 90 0 Z" />
        <path
            android:name="Ring"
            android:strokeColor="#0094c1"
            android:strokeWidth="5.00000003634922"
            android:strokeMiterLimit="10"
            android:pathData="M 90 9 C 134.735064736 9 171 45.2649352637 171 90 C 171 134.735064736 134.735064736 171 90 171 C 45.2649352637 171 9 134.735064736 9 90 C 9 45.2649352637 45.2649352637 9 90 9 Z" />
    </group>
</vector>

其中一个动画制作者 background_circle_animator.xml如下:

And one of the animators "background_circle_animator.xml" is the following:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:ordering="sequentially"
     android:fillAfter="true">

    <objectAnimator
        android:propertyName="fillAlpha"
        android:valueType="floatType"
        android:valueFrom="0f"
        android:valueTo="1f"
        android:duration="200"/>

    <objectAnimator
        android:duration="700"/>

    <objectAnimator
        android:propertyName="fillAlpha"
        android:valueType="floatType"
        android:valueFrom="1f"
        android:valueTo="0f"
        android:duration="200"/>

</set>

在我的activity_main.xml中,我具有应播放此动画的ImageView:

In my activity_main.xml I have the ImageView that should play this animation:

<ImageView
    android:id="@+id/feedback_ui"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="invisible"/>

最后在我的MainActivity.java中,我具有以下代码:

Finally in my MainActivity.java I have the following code:

ImageView feedbackUI = (ImageView) findViewById(R.id.feedback_ui);
feedbackUI.setImageResource(R.drawable.animated_feedback);

Drawable animation = feedbackUI.getDrawable();
if (animation instanceof Animatable) {
    feedbackUI.setVisibility(View.VISIBLE);
    ((Animatable) animation).start();
}

以下是我的毕业礼物:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "karim.com.testinganimation"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
}

运行此代码时,您应该看到一个白色的圆圈,上面有一个蓝色的环,并且应该

When running this code you should see a white circle with a blue ring on top of it and it should fade in and then fade out.

我在API> 21设备上运行了这段代码,它运行得很完美。

I ran this code on API > 21 device and it ran perfectly.

当我在具有API 15的设备上运行该动画时,一旦动画开始,我将收到以下崩溃信息:

When I run it on a device with API 15 I get the following crash as soon as I the animation starts:

D/PropertyValuesHolder(19300): Can't find native method using JNI, use reflectionjava.lang.NoSuchMethodError: no method with name='set' signature='(F)V' in class Landroid/support/graphics/drawable/VectorDrawableCompat$VFullPath;
E/PropertyValuesHolder(19300): Couldn't find setter/getter for property null with value type float
E/PropertyValuesHolder(19300): Couldn't find no-arg method for property null: java.lang.NoSuchMethodException: get []
D/AndroidRuntime(19300): Shutting down VM
W/dalvikvm(19300): threadid=1: thread exiting with uncaught exception (group=0x40a9e1f8)
E/AndroidRuntime(19300): FATAL EXCEPTION: main
E/AndroidRuntime(19300): java.lang.NullPointerException
E/AndroidRuntime(19300):    at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:513)
E/AndroidRuntime(19300):    at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:392)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:544)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator.start(ValueAnimator.java:934)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator.start(ValueAnimator.java:957)
E/AndroidRuntime(19300):    at android.animation.ObjectAnimator.start(ObjectAnimator.java:370)
E/AndroidRuntime(19300):    at android.animation.AnimatorSet$DependencyListener.startIfReady(AnimatorSet.java:705)
E/AndroidRuntime(19300):    at android.animation.AnimatorSet$DependencyListener.onAnimationEnd(AnimatorSet.java:659)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1040)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator.access$900(ValueAnimator.java:49)
E/AndroidRuntime(19300):    at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:675)
E/AndroidRuntime(19300):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19300):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(19300):    at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(19300):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(19300):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(19300):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(19300):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(19300):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  164):   Force finishing activity karim.com.testinganimation/.MainActivity

如何解决此问题,因为在具有API级别15的设备上运行非常关键。

How can I fix this issue as it is very critical to run on devices with API level 15.

推荐答案

我没有API 15设备或仿真器对此进行测试,但是在我看来,您对中间的objectAnimator不满意:

I don't have an API 15 device or emulator to test this, but it seems to me it's not happy with your middle objectAnimator:

 <objectAnimator
    android:duration="700"/>

错误消息的某些部分,例如找不到属性为null的setter / getter,表明它是试图设置一个动画器,但是由于没有动画器应进行动画处理的详细信息,因此它崩溃了。

Parts of your error message such as 'Couldn't find setter/getter for property null' suggest it's trying to set up an animator, but as there are no details of what the animator should be animating, it's crashing.

假定此objectAnimator的目的只是导致动画矢量在淡出之前暂停,我建议尝试这样的操作:

Assuming the purpose of this objectAnimator is just to cause the animated vector to pause before fading out, I would suggest trying something like this:

<objectAnimator
    android:propertyName="fillAlpha"
    android:valueType="floatType"
    android:valueFrom="1f"
    android:valueTo="1f"
    android:duration="700"/>

这篇关于Animated Vector Drawable无法与API 15一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆