viewflipper只有下一个动画

时间:2012-02-13 21:20:49

标签: android animation viewflipper

我创建了一个viewflipper,以便在android中的2个视图之间切换。

问题是我想在这两个视图之间使用相同的动画(幻灯片)进行切换。 当我从视图1翻转时它起作用 - >视图2但是当我从视图2翻转时它使用反向动画 - >查看1

当我使用3个视图时,同样的事情发生,翻转1-> 2-> 3时一切正常,但它在3> 1期间使用反向动画

任何想法?

1 个答案:

答案 0 :(得分: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);