Android Onboarding Hop Animation

Hop Your Feature

Let’s Try

One Hop

val animation = textViewHop
.animate()
.translationYBy(-40f)
.setDuration(200)

animation.withEndAction {
textViewHop.animate().translationYBy(40f).duration = 200
}

How to loop this?

animationHandler.post(new Runnable(){
@Override
public void run(){
//Hop animation
animationHandler.postDelayed(this, 1000);
}
}
);
animationHandler.post(object : Runnable {
override fun run() {
// Hop animation
animationHandler.postDelayed(this, 1000)
}
})
private val animationHandler = Handler()
private lateinit var animationRunnable: Runnable

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
animationRunnable = Runnable { animationFunction() }
animationHandler.post(animationRunnable)
}
private fun animationFunction() {
val animation = textViewHop
.animate()
.translationYBy(-40f)
.setDuration(200)
animation.withEndAction {
textViewHop.animate().translationYBy(40f).duration = 200
}
animationHandler.postDelayed(animationRunnable, 1000)
}
animationHandler.post(object : Runnable {
override fun run() {
val animation = linearLayoutBottomSheet
.animate()
.translationYBy(-40f)
.setDuration(200)
animation.withEndAction {
linearLayoutBottomSheet.animate().translationYBy(40f).duration = 200
}
animationHandler.postDelayed(this, 1000)
}
})
animationHandler.post(new Runnable() {
@Override
public void run() {
ViewPropertyAnimator viewPropertyAnimator =
linearLayoutBottomSheet.animate().translationYBy(-40f).setDuration(200);
viewPropertyAnimator.withEndAction(new Runnable() {
@Override
public void run() {
linearLayoutBottomSheet.animate().translationYBy(40f).setDuration(200);
}
});
animationHandler.postDelayed(this, 1000);
}
});

The result:

Android Developer @Teckro.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store