Android gives us a lot of animation, how to use these animations to achieve the effect we need? Today, we summarize the Objectanimator animation control events.
The layout file for this purpose has only two controls: ImageView and button, not in here, let's look at the implementation of the activity:
Public classTwoactivityextendsactivity{Privatebutton button;PrivateImageView ImageView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Button=(Button) Findviewbyid (R.id.button);ImageView=(ImageView) Findviewbyid (R.id.imageview); Button.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {Objectanimator Animator=NewObjectanimator (). Offloat (ImageView, "alpha", 0F, 1F); Animator.setduration (1000); Animator.addlistener (NewAnimator.animatorlistener () {@Override Public voidOnanimationstart (Animator Animator) {//Start Animation EventToast.maketext (twoactivity. This, "animation Start", Toast.length_short). Show (); } @Override Public voidonanimationend (Animator Animator) {//End Animation EventToast.maketext (twoactivity. This, "End of animation", Toast.length_short). Show (); } @Override Public voidOnanimationcancel (Animator Animator) {//Cancel Event} @Override Public voidonanimationrepeat (Animator Animator) {//Recurring Events } }); Animator.start (); } }); }}
Here is the main point for you to introduce the Objectanimator AddListener () method, you can see that the implementation of this method needs to implement its internal four built-in methods, we often use the Onanimationend () method, used to render the user after the end of the animation control.
Objectanimator control of Android properties animation