All along, the completion of the animation is the use of aniamtionset, put all the animation in a set, this is the traditional animation, but there are a lot of drawbacks, such as the code below, layout files are composed of a iamgeview and a button, Add the following listener events to the button and Imagevew:
1 @Override2 Public voidOnClick (view view) {3 //TODO auto-generated Method Stub4 Switch(View.getid ()) {5 //adding monitoring to ImageView6 Caser.id.img:7Toast.maketext (mainactivity. This, "clicked", Toast.length_short). Show ();8 Break;9 //add listener to the button, which is ImageView 180 pixels along the XY axis diagonalTen CaseR.id.btn_move: One { ATranslateanimation trans =NewTranslateanimation (0,180,0,180); -Trans.setduration (1000); -Trans.setfillafter (true);; the img.startanimation (trans); - } -}
When the program finishes running, you will find a strange phenomenon:
When you click on the original location of the image, the instant picture has moved away, but you click on the original blank location of the image, will still trigger the ImageView click event, and you click on the mobile image, he will not trigger ImageView click event.
Therefore, the use of traditional animation has some drawbacks, the following is a simple use of property animation.
1 objectanimator.offloat (img, "Translationy", 0f,180f). Setduration (+).start (); 2 objectanimator.offloat (img, "Translationx", 0f,180f). Setduration (+). Start ();
When you use Objectanimator to control the animation, you only need to call Offloat (), and the parameters of this method represent:
* 1. Objects to be manipulated
* 2, to manipulate the properties of the object
* 3, the range of animation changes
When you change the monitor of the button to the above code, you will not have the strange phenomenon mentioned above, and you can realize the effect of "where to hit".
Do not accumulate Kuibu, no to thousands of miles, no small stream, no to become Jianghai
Use property Animation (Animator) to complete an animation