Http://www.cnblogs.com/eoiioe/archive/2012/08/29/2662546.html
Android Write animation effect is not the general trouble, online looking for a long time, finally solved the problem of animation, summary records to encourage each other. Only the horizontal movement effect is described, similar to the vertical direction.
Public voidSlideview (Final floatP1,Final floatp2) {translateanimation animation=NewTranslateanimation (P1, p2, 0, 0); Animation.setinterpolator (Newovershootinterpolator ()); Animation.setduration (Durationmillis); Animation.setstartoffset (Delaymillis); Animation.setanimationlistener (NewAnimation.animationlistener () {@Override Public voidOnanimationstart (Animation Animation) {} @Override Public voidonanimationrepeat (Animation Animation) {} @Override Public voidonanimationend (Animation Animation) {intleft = View.getleft () + (int) (p2-p1); inttop =View.gettop (); intwidth =view.getwidth (); intHeight =view.getheight (); View.clearanimation (); View.layout (left, top, left)+width, top+height); } }); View.startanimation (animation);}Invocation Example:Move to the target position Slideview (0, distance); move back from the target position
Slideview (0,-distance);
Problems encountered in the process:
1, after the completion of the animation, the view back to the original
The animation is only written so much at the beginning that the view will return to its original position when the animation is finished.
Try using Animation.setfillafter (true) after checking the data; View no longer returns to its original position, but there is a 2nd question
2, click the button, the view in the initial position will flash first, and then perform the animation
After checking the data, we know that animation.setfillafter (true); Just moved the view to the target location, but the view-bound Click event is still in place, causing the click to Flash First
Check the data to find a solution: No setfillafter, by setting the view position to achieve the effect, add the following code
Animation.setanimationlistener (New Animation.animationlistener () { @Override public void Onanimationstart ( Animation Animation) { } @Override public void Onanimationrepeat (Animation Animation) { } @ Override public void Onanimationend (Animation Animation) { int left = View.getleft () + (int) (P2-P1); int top = View.gettop (); int width = view.getwidth (); int height = view.getheight (); View.clearanimation (); View.layout (left, top, left+width, top+height); });
Set the location of the view after the animation finishes (Onanimationend) and Clearanimation ()
Note: clearanimation () must be executed before layout (l,t,r,b), otherwise it will go wrong ~ this is done ~
Android Mobile View animation problem