After the TranslateAnimation animation is moved, the x y coordinates of the ImageView itself will not change.

Source: Internet
Author: User

For example:

TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) is relative to its own move, but after moving it, the x y value of the View itself of the animation remains unchanged, when you manually set coordinates, as shown in figure

View. setX (x );

View. setY (y );

The display position of the view is not in the current x and y coordinates, but in the position after anim is executed relative to the position, and the event can be triggered at this position.

Solution: Use Animation listeners

Instance:

ImageView img = new ...... Create ImageView


TranslateAnimation anim = new TranslateAnimation (0, x, 0, y );


Anim. setFillAfter (true); // sets the value to be moved and left in the current position. No result is returned.


Anim. setDuration (500 );

Anim. setInterpolator (macitator, android. R. anim. accelerate_decelerate_interpolator );


Img. startAnimation (anim );

// Set the animation listener, clear the img animation when the listener ends, and set the img x and y coordinates.

Anim. setAnimationListener (new AnimationListener (){

@ Override

Public void onAnimationStart (Animation animation ){

// TODO Auto-generated method stub

}

@ Override

Public void onAnimationRepeat (Animation animation ){

// TODO Auto-generated method stub

}

@ Override

Public void onAnimationEnd (Animation animation ){

// TODO Auto-generated method stub

Img. clearAnimation ();

Img. setX (x );

Img. setY (y );

}

});


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.