Reputation: 139
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
Upvotes: 2
Views: 2339
Reputation: 1710
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
Upvotes: 4
Reputation: 627
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));
}
Upvotes: 2