Android TranslateAnimation Tutorial

TranslateAnimation is a type of animation effect provided by the Android system that allows a View to move along a specified path on the screen. Below are the steps for using TranslateAnimation:

  1. Create a TranslateAnimation object:
TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 100);

The code above shows the creation of a translation animation from (0,0) to (100,100).

  1. Set the duration of the animation:
translateAnimation.setDuration(1000); // 设置动画持续时间为1秒
  1. Set animation repeat count:
translateAnimation.setRepeatCount(Animation.INFINITE); // 设置动画重复次数为无限次
  1. Do you want the animation to end and maintain the final state?
translateAnimation.setFillAfter(true); // 设置动画结束后保持最后的状态
  1. Set animation for View.
view.startAnimation(translateAnimation);

The code above shows how to add a translation animation effect to the view.

By following the steps above, you can achieve a translation animation effect for a View using TranslateAnimation.

bannerAds