I. XML
1. A picture, a text description (what controls are needed to choose by yourself)
<!--horse race lamp--> <RelativeLayout android:id="@+id/homepager_RelativeLayout_pao" android:layout_width="match_parent" android:layout_height="@dimen/dp_50" android:layout_below="@+id/homepager_ViewPager_jiu_layout" android:orientation="horizontal"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/homepager_pao_SimpleDraweeView" android:layout_width="@dimen/dp_50" android:layout_height="@dimen/dp_50" /> <TextView android:id="@+id/homepager_pao_TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" /> </RelativeLayout>
II. java code
1. Create three animations
First animation: y-axis translation coordinates: 0,0; (middle display area)
Second animation: y-axis translation - coordinates: 0, - 50; (move from middle to top)
Third Animation: y-axis translation coordinates: 50,0; (move from bottom to middle)
2. Add animation to the collection (it must be added in the order above)
3. Each animation in the set is executed for two seconds
4. Start execution
5. Set the animation to play infinitely (because there is no setRepeatCount() method in the animation set, you must
animatorSet.addListener(new Animator.AnimatorListener() {} executes the animation again in the end method of listening, so that after each end, it will execute again to realize infinite rotation)
6. Set the content (to set the content in the monitoring of animatorTop, when the execution of animatorTop is finished, assign a new value to the content, and then the animation of animatorBottom (from the bottom to the middle) will be executed, so that the user will not see the process of content change. Only a new message can be seen rising from below.)
//horse race lamp private void annimotion() { ObjectAnimator animatorTop = ObjectAnimator.ofFloat(homepager_relativeLayout_pao,"translationY",0,-50); ObjectAnimator animatorBottom = ObjectAnimator.ofFloat(homepager_relativeLayout_pao,"translationY",50,0); ObjectAnimator animator = ObjectAnimator.ofFloat(homepager_relativeLayout_pao,"translationY",0,0); //Create an animation collection animatorSet = new AnimatorSet(); animatorSet.playSequentially(animator,animatorTop,animatorBottom); //Each animation in the collection is executed for two seconds animatorSet.setDuration(2000); //Start animation animatorSet.start(); //Set the contents of running lights animatorTop.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { position++; homepager_pao_textView.setText(jiuBeanList.get(position%jiuBeanList.size()).getName()); homepager_pao_simpleDraweeView.setImageURI(jiuBeanList.get(position%jiuBeanList.size()).getIcon()); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); //Animate unlimited playback animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { //Execute after each animation animatorSet.setDuration(2000); animatorSet.start(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); }