Skip to content

Instantly share code, notes, and snippets.

@siscofran999
Created July 19, 2021 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siscofran999/87a4d75188c0af6128493c1adc3fa7ba to your computer and use it in GitHub Desktop.
Save siscofran999/87a4d75188c0af6128493c1adc3fa7ba to your computer and use it in GitHub Desktop.
sample class implement move animation
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