Listener events for Android property animations

Source: Internet
Author: User

Overall very simple, directly on the code bar. Activity_main.xml:

1<?xml version= "1.0" encoding= "Utf-8"?>2<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Xmlns:tools= "Http://schemas.android.com/tools"4Android:layout_width= "Match_parent"5android:layout_height= "Match_parent"6Tools:context= "Com.example.administrator.animator_demo2. Mainactivity ">7 8<Button9Android:id= "@+id/btn_click"TenAndroid:layout_width= "Wrap_content" Oneandroid:layout_height= "Wrap_content" AAndroid:layout_centerinparent= "true" -android:text= "click"/> -  the</RelativeLayout>

Then there is the Java code, Mainactivity.java:

1  PackageCom.example.administrator.animator_demo2;2 3 ImportAndroid.animation.Animator;4 ImportAndroid.animation.AnimatorListenerAdapter;5 ImportAndroid.animation.ObjectAnimator;6 ImportAndroid.os.Bundle;7 Importandroid.support.v7.app.AppCompatActivity;8 ImportAndroid.view.View;9 ImportAndroid.widget.Button;Ten ImportAndroid.widget.Toast; One  A  Public classMainactivityextendsAppcompatactivityImplementsView.onclicklistener { -  -     PrivateButton Btn_click; the  - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); - Initview (); +     } A  at     Private voidInitview () { -Btn_click =(Button) Findviewbyid (R.id.btn_click); -Btn_click.setonclicklistener ( This); -     } -  - @Override in      Public voidOnClick (View v) { -         Switch(V.getid ()) { to              CaseR.id.btn_click: + //StartAnimator1 (); -                 /** the * StartAnimator1 () method, rewrite the four listening methods, because sometimes we * * We don't need to monitor that much, just the Onanimationend () method.  $ * Then we will choose the way to use StartAnimator2 (). (two different execution effects)Panax Notoginseng                  * */ - StartAnimator2 (); the                  Break; +         } A     } the  +     Private voidStartAnimator1 () { -         //Transparent animations $Objectanimator animator = Objectanimator.offloat (Btn_click, "alpha", 0F, 1F); $Animator.setduration (1000); -         //set up listening for animations -Animator.addlistener (NewAnimator.animatorlistener () { the @Override -              Public voidOnanimationstart (Animator animation) {Wuyi  the             } -  Wu @Override -              Public voidonanimationend (Animator animation) { About                 /** $ * In most cases, we're going to listen to this, what happens after the animation is over - * Here, we only pop a toast.  -                  * */ -Toast.maketext (mainactivity. This, "End of animation execution", Toast.length_short). Show (); A             } +  the @Override -              Public voidOnanimationcancel (Animator animation) { $  the             } the  the @Override the              Public voidonanimationrepeat (Animator animation) { -  in             } the         }); the Animator.start (); About     } the  the     Private voidStartAnimator2 () { the         //Transparent animations +Objectanimator animator = Objectanimator.offloat (Btn_click, "alpha", 0F, 1F); -Animator.setduration (1000); the         //set up listening for animationsBayiAnimator.addlistener (NewAnimatorlisteneradapter () { the @Override the              Public voidonanimationend (Animator animation) { -                 Super. Onanimationend (animation); -Toast.maketext (mainactivity. This, "End of animation execution", Toast.length_short). Show (); the             } the         }); the Animator.start (); the     } -}

Listener events for Android property animations

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.