0

I have a problem, I'm trying to make child in ViewAnimator, which will slide from bottom. And after back press, it will slide down again.

Animation anim = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
anim.setDuration(350);
anim.setInterpolator(new AccelerateInterpolator());

viewFlipper.setInAnimation(anim);
viewFlipper.setOutAnimation(null);
viewFlipper.setDisplayedChild(2);

onBackPress:

Animation anim = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f
);
        anim.setDuration(350);
        anim.setInterpolator(new AccelerateInterpolator());

        viewFlipper.setInAnimation(null);
        viewFlipper.setOutAnimation(anim);
        viewFlipper.setDisplayedChild(0);

But my problem is that when I click on button the first time, the Screen goes black and Child slides up. When I click on back button, everything is ok. (child slides down and behind is first screen...

Any help?

EDIT:

Animation inAnim = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
anim.setDuration(350);
anim.setInterpolator(new AccelerateInterpolator());

Animation outAnim = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outAnim.setDuration(350);
outAnim.setInterpolator(new AccelerateInterpolator());

viewFlipper.setInAnimation(inAnim);
viewFlipper.setOutAnimation(outAnim);
viewFlipper.setDisplayedChild(2);
Michal Heneš
  • 353
  • 2
  • 4
  • 19

2 Answers2

0

This:

 viewFlipper.setOutAnimation(null);

and

 viewFlipper.setInAnimation(null);

Essentially it tells the framework to HIDE the first view, and then animate the second one.

You have to supply the opposite direction animation. This can be achieved using just two animations. Simply use the slide in and slide out for showing next view, and the same two animation for the opposite, but you have to reverse them - preferably by using some setRepeatMode(Animation.REVERSE) - refer to this question or just declare additional reversed animations.

Community
  • 1
  • 1
Jitsu
  • 769
  • 3
  • 7
  • I don't know if you understand my expectation, but I want to have one child fixed in place, and second that will slide up and down. – Michal Heneš Aug 27 '14 at 18:02
  • Try to anim.setFillBefore(true) or anim.setFillAfter(true) for different result. – Jitsu Aug 28 '14 at 09:45
0
Animation inAnim = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
anim.setDuration(350);
anim.setInterpolator(new AccelerateInterpolator());

Animation outAnim = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outAnim.setDuration(350);
outAnim.setInterpolator(new AccelerateInterpolator());

viewFlipper.setInAnimation(inAnim);
viewFlipper.setOutAnimation(outAnim);
viewFlipper.setDisplayedChild(2);
Michal Heneš
  • 353
  • 2
  • 4
  • 19