2012-02-21 14 views
1

私はAnimationSetを使ってアニメーションシーケンスに大きな問題を抱えています。私は以下のアニメーションをしたい:AnimationSetがアニメーションの組み合わせを正しく実行しない理由を教えてください。

0から100%までスケールアップし、次にAからBに移動し、同時にアルファを1.0から0.5および0.5から1.0に移動する。

私はこの順序で複数の問題を抱えているが、2つの専攻があります:私はスタートオフセットを計算し、各アニメーションの継続時間が正しく、移動アニメーションが終了し、私はまだだという事実にもかかわらず

  • アルファ0.5では1.0に戻ってBの位置に戻って1.0に戻ります。

  • アルファアニメーションが1.0に達しない場合があります。0.9で停止するか、1.0に達し、画面が再描画され0.9 。

私の知る限り、AnimatorSetはアニメーションを順番に評価しますが、startOffsetを使用すると、それらを同時に実行できます。

は、ここに私のコードの一部です:AnimationSetは私が期待してい何をしない理由

public void moveAndDrawPart(ImageView partToMove, Button buttonPressed) 
    { 
     // Save current data for listener. 
     lastPartToMove = partToMove; 
     lastButtonPressed = buttonPressed; 

     // Animate part movement. 
     animatePart(partToMove, buttonPressed); 
    } 

    // Animate part movement from original position to the final position. 
    private void animatePart(ImageView part, Button destination) 
    { 
     // Make part visible. 
     part.setVisibility(ImageView.VISIBLE); 
     part.bringToFront(); 

     AnimationSet animator = new AnimationSet(false); 
     animator.setFillAfter(false); 

     // Make part appears by scaling up. 
     ScaleAnimation scaleUp = new ScaleAnimation((float)0.0, (float)1.0, (float)0.0, (float)1.0, ScaleAnimation.RELATIVE_TO_SELF, (float)0.5, ScaleAnimation.RELATIVE_TO_SELF, (float)0.5); 
     scaleUp.setInterpolator(new DecelerateInterpolator()); 
     scaleUp.setFillAfter(true); 
     scaleUp.setStartOffset(0); 
     scaleUp.setDuration(500);  

     // Move from origin to final position. 
     TranslateAnimation move = new TranslateAnimation(0, destination.getX()-part.getX(), 0, destination.getY()-part.getY()); 
     move.setInterpolator(new DecelerateInterpolator()); 
     move.setFillAfter(true); 
     move.setStartOffset(scaleUp.getDuration()); 
     move.setDuration(600); 

     // Make part semi-transparent. 
     AlphaAnimation alpha = new AlphaAnimation((float)1.0, (float)0.5); 
     alpha.setInterpolator(new LinearInterpolator()); 
     alpha.setFillAfter(true); 
     alpha.setRepeatCount(1); 
     alpha.setRepeatMode(AlphaAnimation.REVERSE); 
     alpha.setStartOffset(scaleUp.getDuration()); 
     alpha.setDuration(300); 

     animator.addAnimation(scaleUp); 
     animator.addAnimation(move); 
     animator.addAnimation(alpha); 
     animator.setAnimationListener(this); 

     part.startAnimation(animator); 
    } 

    // Reposition part at final position to redraw it properly. 
    private void repositionPart(ImageView part, Button destination) 
    { 
     // Clear part animation to bring back drawn position to original. 
     part.clearAnimation(); 

     part.setX(destination.getX()); 
     part.setY(destination.getY()); 
    } 

    public void onAnimationStart(Animation animation) 
    { 
     // This variable is used to workaround a glitch: clearAnimation() 
     // causes onAnimationEnd() to be called twice. 
     animationDone = false; 
    } 

    public void onAnimationEnd(Animation animation) 
    { 
     // This variable is used to workaround a glitch: clearAnimation() 
     // causes onAnimationEnd() to be called twice. 
     if(animationDone == false) 
     { 
     animationDone = true; 

     if((lastPartToMove != null) && (lastButtonPressed != null)) 
     { 
      // Reposition the part. 
      repositionPart(lastPartToMove, lastButtonPressed); 
     } 
     else 
     { 
      Toast.makeText(myAct, "Major error occured. Last references are not set!", Toast.LENGTH_LONG).show(); 
     } 
     } 
    } 

あなたは私に教えてもらえますか?

ところで、私はこの問題をHoneycomb 3.2エミュレータで試しています。

+0

アニメーションの終わりに1.0に達しないことがあるアルファについては、私はデバイス上でそれをテストし、アプリケーションでハードウェアアクセラレーションをアクティブにするまで同じ結果を得ました。これ以降、アルファは常に1.0に達すると思われます。しかし、私はまだエミュレータ上で奇妙な動作を取得します。 – DavidH

+0

誰かが自分のコードを試して、それが不具合かどうかを確認するチャンスがありますか? – DavidH

答えて

0

アニメーションまたはアニメーションセットを作成した後、それをLayoutのようなViewクラスにロードする必要があります。 あなたは、このようにそのレイアウトをアニメーション化することができます

TranslateAnimation trans = new TranslateAnimation(0, 0, 0, height/2); 
     trans.setDuration(1000); 


     myAnimationSet.addAnimation(trans); 

     final RelativeLayout splash_relative = (RelativeLayout) findViewById(R.id.relativeLayout_splash); 
     splash_relative.startAnimation(myAnimationSet); 

、それが動作します。私はそれが助けと願っています。

関連する問題