我一直在尝试在API等级为15的设备上运行动画矢量Drawable。
以下是我的动画矢量“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>
drawable“feedback.xml”包含以下内容:
<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”如下:
<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:
<ImageView
android:id="@+id/feedback_ui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"/>
最后在我的MainActivity.java中,我有以下代码:
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'
}
运行此代码时,您应该看到一个白色圆圈,顶部有一个蓝色圆环,它应该淡入然后淡出。
我在API上运行此代码&gt; 21设备,它运行完美。
当我在使用API 15的设备上运行它时,动画一开始就会出现以下崩溃:
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的设备上运行非常关键。
答案 0 :(得分:0)
我没有API 15设备或模拟器来测试这个,但在我看来,它对你的中间对象不满意:
<objectAnimator
android:duration="700"/>
您的错误消息的部分内容,例如&#39;无法找到属性为null的setter / getter&#39;建议它试图建立一个动画师,但由于没有动画师应该制作动画的细节,它会崩溃。
假设此objectAnimator的目的只是让动画矢量在淡出之前暂停,我建议尝试这样的事情:
<objectAnimator
android:propertyName="fillAlpha"
android:valueType="floatType"
android:valueFrom="1f"
android:valueTo="1f"
android:duration="700"/>