動畫我使用從支持庫23.2.0動畫載體,像這樣:AnimatedVectorDrawable在支持庫和 「pathData」
我試圖動畫 「pathData」(將線條變形到另一個)。我的代碼看起來像這樣。
繪製/ ic_done.xml:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:name="tick"
android:pathData="M4.8,12L9,16.2L20,8"
android:strokeColor="#FF000000" />
</vector>
繪製/ ic_done_animated.xml:
<?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/ic_done">
<target
android:name="tick"
android:animation="@animator/tick_path_animation" />
</animated-vector>
動畫/ tick_path_animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L4.8,12L4.8,12"
android:valueTo="M4.8,12L9,16.2L9,16.2"
android:valueType="pathType" />
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L9,16.2L9,16.2"
android:valueTo="M4.8,12L9,16.2L20,8"
android:valueType="pathType" />
</set>
Java代碼:
ImageView vImgAnimated = findByViewId(R.id.img);
AnimatedVectorDrawableCompat animatedVector = AnimatedVectorDrawableCompat.create(getContext(), R.drawable.ic_done_animated);
vImgAnimated.setImageDrawable(animatedVector);
animatedVector.start();
它運作良好,新的設備上API級別21,但我有API級別16上裝置了一個問題:
java.lang.NumberFormatException: Invalid int: "M4.8,12L4.8,12L4.8,12"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:258)
at android.animation.AnimatorInflater.loadObjectAnimator(AnimatorInflater.java:161)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:117)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:126)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:93)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:72)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:377)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.create(AnimatedVectorDrawableCompat.java:142)
根據文章android-support-library-232動畫向量(AnimatedVectorDrawableCompat)應該得到支持回到API級別11。
它看起來像讀取時失敗valueFrom屬性來自tick_path_animation.xml。此屬性類型「pathType」可能不受支持(但?)。任何想法如何解決這個問題?
嘗試通過wnafee使用Vector-Compat https://github.com/wnafee/vector-compat,我測試了路徑變形,效果很好 –
您的問題已在支持庫25.4.0+:https:// developer中得到解決。 android.com/topic/libraries/support-library/revisions.html#25-4-0 – Frank
對於平臺上的路徑變形
Tarek360