Skip to content

Instantly share code, notes, and snippets.

@gabrielbmoro
Created September 24, 2019 02:23
Show Gist options
  • Save gabrielbmoro/9d1f507aff1a0c96be0020aa6cfed832 to your computer and use it in GitHub Desktop.
Save gabrielbmoro/9d1f507aff1a0c96be0020aa6cfed832 to your computer and use it in GitHub Desktop.
Simple animation using translation property
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
var multiplier = 1
val lastMultiplier = 2
val viewToAnimate : View = findViewById(R.id.vwContent)
findViewById<Button>(R.id.btnDispare).apply{
setOnClickListener {
ObjectAnimator.ofFloat(
viewToAnimate,
"translationX", //property
multiplier * resources.getDimension(R.dimen.distanceX) //distance
).apply {
duration = 500
start()
}
if (multiplier < lastMultiplier) multiplier++
else multiplier = 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment