I'm making a Splash Screen and I want the image view to continuously go up then down like it's levitating. This will happen while the database loads in the background (AsyncTask). I have tried animating views but it is only in a single direction and just once. How do I accomplish this? Thank you in advance :D
Asked
Active
Viewed 2,129 times
1
-
I edited my answer and changed the code a bit – David Seroussi Apr 22 '16 at 13:59
-
all i have to do is to change the timing but it works as i wanted to. thank you very much! :D – Yeol Apr 22 '16 at 17:27
2 Answers
3
What I would do is animate views like you did before,with a kind of an infinite loop inside onAnimationEnd :
//in onPreExecute do levitate(ivSplashLogo, 300, true)
//in onPostExecute do levitate(ivSplashLogo, 300, false)
public void levitate (final View movableView,final float Y,boolean animated){
if(animated) {
final long yourDuration = 200;
final TimeInterpolator yourInterpolator = new DecelerateInterpolator();
movableView.animate().
translationYBy(Y).
setDuration(yourDuration).
setInterpolator(yourInterpolator).
setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
levitate(movableView, -Y, true);
}
});
}
}
I haven't tried this yet but you could give it a go and tell me

David Seroussi
- 1,650
- 2
- 17
- 34
-
I am unaware of what Interpolator is for and how it differs from Duration. – Yeol Apr 22 '16 at 12:47
-
1An Interpolator is a Bezier curve that will apply different effects to the animation. [Here](https://www.youtube.com/watch?v=OMOJxBe9KGg) is a video that will show you the results of various interpolators. Here is the [documentation](http://developer.android.com/reference/android/view/animation/Interpolator.html) if you want – David Seroussi Apr 22 '16 at 12:50
-
i see. thanks! im calling it from the OnProgressUpdate but it's not moving : – Yeol Apr 22 '16 at 13:17
2
Bottom to top :
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="100%p"
android:toYDelta="0%p" />
Top to Bottom :
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%p"
android:toYDelta="100%p" />
Code :
if (findViewById(R.id.llIncludeBottom).getVisibility() == View.VISIBLE) {
findViewById(R.id.llIncludeBottom).setVisibility(View.GONE);
findViewById(R.id.llIncludeBottom).setAnimation(
AnimationUtils.loadAnimation(this, R.anim.top_bottom));
} else {
findViewById(R.id.llIncludeBottom).setVisibility(View.VISIBLE);
findViewById(R.id.llIncludeBottom).setAnimation(
AnimationUtils.loadAnimation(this, R.anim.bottom_top));
}

Nik Patel
- 627
- 7
- 21