2012-02-13 10 views
2

私はアンドロイドの2つのビューの間でフリップするためにビューフリッパを作成しました。viewflipper only nextアニメーション

問題は、これらの2つのビューの間で反転したいということです。同じアニメーション(スライドイン)を使用しています。 ビュー1からビュー2に切り替えるときに機能しますが、ビュー2からフリップしているときに反転アニメーションを使用します。

ビューを3回使用すると同じことが起こります。 - > 2-> 3ですが、3> 1の間に逆のアニメーションを使用します

アイデア?

答えて

3

あなたはこのように行う場合は、アニメーションやページ反転の完全な制御になります。

//ViewFlipper 
ViewFlipper flipper; 
//Four different animations 
Animation OutToRight; 
Animation OutToLeft; 
Animation InFromRight; 
Animation InFromLeft;   

OutToRight = new TranslateAnimation(
       Animation.RELATIVE_TO_PARENT, 0.0f,  Animation.RELATIVE_TO_PARENT, +1.0f, 
       Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
      ); 
OutToRight.setDuration(500); 
     OutToRight.setInterpolator(new AccelerateDecelerateInterpolator()); 

     OutToLeft = new TranslateAnimation(
       Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, 
       Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
      ); 
     OutToLeft.setDuration(500); 
    OutToLeft.setInterpolator(new AccelerateDecelerateInterpolator()); 

    InFromRight = new TranslateAnimation(
       Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
       Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
      ); 
    InFromRight.setDuration(500); 
     InFromRight.setInterpolator(new AccelerateDecelerateInterpolator()); 

    InFromLeft = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
       ); 
    InFromLeft.setDuration(500); 
    InFromLeft.setInterpolator(new AccelerateDecelerateInterpolator()); 

    //Animating Left to page 1 

    flipper.setInAnimation(InFromLeft); 
    flipper.setOutAnimation(OutToRight); 
    flipper.setDisplayedChild(1); 

    //Animating right to page 2 
    flipper.setInAnimation(InFromRight); 
    flipper.setOutAnimation(OutToLeft); 
    flipper.setDisplayedChild(2); 

+0

私はいつも右のアニメーション化したい場合は何? – Vincenzo

+0

その場合は、flipper.setInAnimation(InFromRight)を設定します。 flipper.setOutAnimation(OutToLeft);それらを変更しないでください。これらのアニメーションは、それ以降のsetDisplayedChildコールのために使用されます – andrrs

+0

素晴らしい、ありがとう! – Vincenzo