Created
September 24, 2019 02:23
-
-
Save gabrielbmoro/9d1f507aff1a0c96be0020aa6cfed832 to your computer and use it in GitHub Desktop.
Simple animation using translation property
This file contains hidden or 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
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