我创建了一个 viewflipper 以便在 android 中的 2 个 View 之间翻转。
问题是我想使用相同的动画在这两个 View 之间翻转(滑入)。 当我从 View 1 -> View 2 翻转时它有效,但当我从 View 2 -> View 1 翻转时它使用反向动画
当我使用 3 个 View 时,也会发生同样的情况,翻转 1->2->3 时一切正常,但在 3->1 期间使用反向动画
有什么想法吗?
最佳答案
如果您这样做,您将完全控制动画和翻页:
//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);
关于android - viewflipper仅下一个动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9268199/