Created
July 19, 2021 16:40
-
-
Save siscofran999/87a4d75188c0af6128493c1adc3fa7ba to your computer and use it in GitHub Desktop.
sample class implement move animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity2 : AppCompatActivity(), Animation.AnimationListener { | |
private lateinit var binding: ActivityMain2Binding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMain2Binding.inflate(layoutInflater) | |
setContentView(binding.root) | |
binding.img.setOnClickListener { | |
animationMove(R.anim.move_top) | |
TimeUnit.MILLISECONDS.sleep(1600) | |
animationMove(R.anim.move_bottom) | |
} | |
} | |
private fun animationMove(animXml: Int) { | |
val animation = AnimationUtils.loadAnimation(this, animXml) | |
animation.setAnimationListener(this) | |
Handler(Looper.getMainLooper()).postDelayed( | |
{ binding.img.startAnimation(animation) }, | |
1500 | |
) | |
} | |
override fun onAnimationStart(p0: Animation?) {} | |
override fun onAnimationEnd(p0: Animation?) {} | |
override fun onAnimationRepeat(p0: Animation?) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment