Use property Animation (Animator) to complete an animation

Source: Internet
Author: User

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

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.