2012-02-13 80 views
2

我已經創建了一個viewflipper爲了在android中的2個視圖之間翻轉。viewflipper只有下一個動畫

問題是我想在這兩個視圖之間翻轉使用相同的動畫(slide in)。 它工作時,我從視圖1 - >視圖2翻轉,但它使用反轉動畫時,我從視圖2翻轉 - >查看1

同樣的事情發生時,我使用3個視圖,一切都很好,當翻轉1 - > 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 2012-02-14 13:35:22

+0

在這種情況下,請設置flipper.setInAnimation(InFromRight); flipper.setOutAnimation(OutToLeft);並且不要改變它們。這些動畫隨後會被用於任何後續的setDisplayedChild調用 – andrrs 2012-02-14 18:44:16

+0

太棒了,謝謝! – Vincenzo 2012-02-14 20:54:52