I need this for a project pre API11.
Im looking for a way to add a view in from right, that will cause the current full screen view to move out to left as to allow the new view to be visibe in the screen.
the new view is about 1/3 of the screen width so thats the distance the current fusll screen view should move out of the screen.
i have tired various solutions with TranslateAnimation(), although im happy with the animation, i'm having issues with all the clickable areas in the original view not being where they are supposed to be.
so i started playing with the layout to position it correctly with negative margin, but after a couple of seconds when a new layout request comes the view is popped back into place. also this solution had a choppy effect when moving the view on the animation end listener.
what would be the most simple solution that has good animation when the new view is entering or exiting and that puts the view in the correct place in terms of layout.
Since you're using API11, use the Animator API. All views have properties now with corresponding setters and getters. To shift a view to the left out of scope, get the width of the screen then do:
View viewToShiftOut = getOutView();
ObjectAnimator outAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", 0, -widthOfScreen);
outAnim.setDuration(1000);
outAnim.start();
This will shift the view and it's contents entirely out of the screen for a duration of 1 second (1000 miliseconds). To shift one in it's place do this:
View viewToShiftIn = getInView();
ObjectAnimator inAnim = ObjectAnimator.ofFloat(viewToShiftIn, "x", widthOfScreen, 0);
inAnim.setDuration(1000);
inAnim.start();
All the properties, clickable areas, etc. will follow the view so you'll be done when the animations finish. You can animate them together like so:
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();
Blog post
EDIT: I noticed you wanted to only shift the view by a 1/3rd, so you can get the amount of pixels to shift each by widthOfScreen/3
.
EDIT 2: Another advantage is you can use it with hardware acceleration without trouble which most 3.0+ tablets have.
Instead of using fillAfter and fillEnabled, as you're probably doing, you will need to programmatically alter your layout in the onAnimationEnd of an AnimationListener to match your desired final positioning.
To remove the flicker, call clearAnimation() on the View you are animating, also in onAnimationEnd.