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.