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 );
}
});