ObjectAnimator Control for Android property animation and androidanimator Animation

Source: Internet
Author: User

ObjectAnimator Control for Android property animation and androidanimator Animation

Android provides us with a lot of animation effects. How can we use these animations to achieve what we need? Today, we will summarize the ObjectAnimator animation control events.

The layout file of this project has only two controls: ImageView and Button, which are not described here. Let's take a look at the implementation of the activity:

Public class TwoActivity extends Activity {private Button button; private ImageView imageView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); button = (Button) findViewById (R. id. button); imageView = (ImageView) findViewById (R. id. imageView); button. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {ObjectAnimator animator = new ObjectAnimator (). ofFloat (imageView, "alpha", 0F, 1F); animator. setDuration (1000); animator. addListener (new Animator. animatorListener () {@ Override public void onAnimationStart (Animator animator) {// starts the animation event Toast. makeText (TwoActivity. this, "animation start", Toast. LENGTH_SHORT ). show () ;}@ Override public void onAnimationEnd (Animator animator) {// ends the animation event Toast. makeText (TwoActivity. this, "animation ends", Toast. LENGTH_SHORT ). show () ;}@ Override public void onAnimationCancel (Animator animator) {// cancel event} @ Override public void onAnimationRepeat (Animator animator) {// duplicate event}); animator. start ();}});}}

Here we will focus on introducing the addListener () method of ObjectAnimator. We can see that four built-in methods are required to implement this method. We often use the onAnimationEnd () method, used to display the control after the animation ends.

Related Article

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.