Android Mobile View animation problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.