2016-12-05 4 views
0

私はベクトル描画可能なアニメーションを持っています。 API 17-24では正常に動作しますが、API 25では問題があります。アニメーションは実行されますが、ベクトルは異なる順序で移動します。ここでAPIのベクトルアニメーション25

は私のベクトルはここでアニメーションここ

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <objectAnimator 
     android:duration="300" 
     android:propertyName="scaleX" 
     android:repeatCount="1" 
     android:repeatMode="reverse" 
     android:valueTo="0.05" 
     android:valueType="floatType"/> 
    <objectAnimator 
     android:duration="300" 
     android:propertyName="translateX" 
     android:repeatCount="1" 
     android:repeatMode="reverse" 
     android:valueTo="155" 
     android:valueType="floatType"/> 
</set> 

iは

 new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       Drawable animation = logo.getDrawable(); 
       if (animation instanceof Animatable) { 
        ((Animatable) animation).start(); 
       } 
      } 
     }, 300); 

それを実行する方法です

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 
       android:drawable="@drawable/logo_vector_white"> 
    <target 
     android:name="eye" 
     android:animation="@animator/blink_eye" /> 
</animated-vector> 

描画可能である私はAnimatedVectorDrawable、API 25から始まることを、発見しました runs on RenderThread。これにより問題が発生した場合は、解決方法を教えてください。私はまた、すべてのアニメーションファイルを単一のxmlにバンドルしようとしましたが、同じ結果が得られました。

+0

異なるバージョンのアニメーションはどのような順序で実行されますか? –

+0

@LewisMcGeary私の答えをご覧ください –

答えて

0

私はベクトルオブジェクトの水平スケールのアニメーションだけを行う必要があります(目を点滅させ、Xで0にスケールして元の状態に戻します)。私はピボットについて知りませんでしたし、もう一つtranslateXアニメーションを使ってベクトルの水平移動を補正しました。この回避策は、RenderThreadで実行を開始したAPI 25まで動作していました。

android:pivotXをグループに追加し、translateXプロパティでobjectAnimatorを削除することで、この問題を修正しました。また、android:valueFrom = "1"を追加しました(API 25アニメーションではアニメーションが瞬時にvalueToに切り替わりました)。

ここでは完全なxmlです。

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:aapt="http://schemas.android.com/aapt" 
       xmlns:tools="http://schemas.android.com/tools" 
       tools:ignore="MissingPrefix"> 

    <aapt:attr name="android:drawable"> 
     <vector xmlns:android="http://schemas.android.com/apk/res/android" 
       android:width="292dp" 
       android:height="108dp" 
       android:viewportHeight="108.0" 
       android:viewportWidth="292.0"> 
      <path 
       android:fillColor="#FFFFFF" 
       android:pathData="M7,12L93,12A7,7 0,0 1,100 19L100,34A7,7 0,0 1,93 41L7,41A7,7 0,0 1,0 34L0,19A7,7 0,0 1,7 12z" 
       android:strokeColor="#00000000" 
       android:strokeWidth="1"/> 

      <group 
       android:name="eye" 
       android:pivotX="160"> 
       <path 
        android:name="right_eye" 
        android:fillColor="#FFFFFF" 
        android:pathData="M161.5,26.5m-16.5,0a16.5,16.5 0,1 1,33 0a16.5,16.5 0,1 1,-33 0" 
        android:strokeColor="#00000000" 
        android:strokeWidth="1"/> 
      </group> 

      <path 
       android:fillColor="#FFFFFF" 
       android:pathData="M7,67L93,67A7,7 0,0 1,100 74L100,89A7,7 0,0 1,93 96L7,96A7,7 0,0 1,0 89L0,74A7,7 0,0 1,7 67z" 
       android:strokeColor="#00000000" 
       android:strokeWidth="1"/> 
      <path 
       android:name="left_eye" 
       android:fillColor="#FFFFFF" 
       android:pathData="M161.5,81.5m-16.5,0a16.5,16.5 0,1 1,33 0a16.5,16.5 1,1 1,-33 0" 
       android:strokeColor="#00000000" 
       android:strokeWidth="1"/> 
      <path 
       android:fillColor="#FFFFFF" 
       android:pathData="M241.46,1.54L289.96,50.04A5,5 119.52,0 1,289.96 57.11L278.07,69A5,5 0,0 1,271 69L222.5,20.5A5,5 57.75,0 1,222.5 13.43L234.39,1.54A5,5 86.11,0 1,241.46 1.54z" 
       android:strokeColor="#00000000" 
       android:strokeWidth="1"/> 
      <path 
       android:fillColor="#FFFFFF" 
       android:pathData="M241.5,106L290,57.5A5,5 60.48,0 0,290 50.43L278.11,38.54A5,5 0,0 0,271.04 38.54L222.54,87.04A5,5 112.86,0 0,222.54 94.11L234.43,106A5,5 0,0 0,241.5 106z" 
       android:strokeColor="#00000000" 
       android:strokeWidth="1"/> 
     </vector> 
    </aapt:attr> 

    <target android:name="eye"> 
     <aapt:attr name="android:animation"> 
       <objectAnimator 
        android:duration="300" 
        android:propertyName="scaleX" 
        android:repeatCount="1" 
        android:repeatMode="reverse" 
        android:valueFrom="1" 
        android:valueTo="0" 
        android:valueType="floatType"/> 
     </aapt:attr> 
    </target> 

</animated-vector> 
関連する問題