Android animate view goes into a screen that pops the current full-screen view

I need this for a pre API11 project.

I am looking for a way to add a view to the right, which will cause the current full-screen view to move to the left to allow the new view to see visibe on the screen.

the new view is about 1/3 of the width of the screen, so that the distance at which the current screen will move from the screen will be less.

I am tired of various solutions using TranslateAnimation (), although I am pleased with the animation, I have problems with all clickable areas in the original view, and not where they should be.

so I started playing with the layout to position it correctly with a negative margin, but after a couple of seconds, when a new layout request appears, the view is reinserted. also this decision had a mutable effect when moving the view to the listener at the end of the animation.

which would be the simplest solution that has good animation when entering or exiting a new view and which puts the view in the right place in the layout plan.

+1
source share
2 answers

Since you are using API11, use the Animator API . Now all views have properties with corresponding setters and getters. To shift the view to the left of the scope, get the width of the screen, and then do:

View viewToShiftOut = getOutView();
ObjectAnimator outAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", 0, -widthOfScreen);
outAnim.setDuration(1000);
outAnim.start();

1 (1000 ). , :

View viewToShiftIn = getInView();
ObjectAnimator inAnim = ObjectAnimator.ofFloat(viewToShiftIn, "x", widthOfScreen, 0);
inAnim.setDuration(1000);
inAnim.start();

, .. , . :

View viewToShiftOut = getOutView();
View viewToShiftIn = getInView();
ObjectAnimator outAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", 0, -widthOfScreen);
ObjectAnimator inAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", widthOfScreen, 0);
outAnim.setDuration(1000);
inAnim.setDuration(1000);
outAnim.start();
inAnim.start();

EDIT: , 1/3, , widthOfScreen/3.

EDIT 2: , - , 3.0+.

+10

, fillAfter fillEnabled, , , , onAnimationEnd AnimationListener, .

, clearAnimation() , onAnimationEnd.

0

All Articles