2016-04-22 70 views
0

我正在制作一个Splash Screen,我希望图像视图能够像悬浮一样不断上升。数据库在后台加载时会发生这种情况(AsyncTask)。我尝试过动画视图,但它只是在一个方向上,只有一次。我该如何做到这一点?预先感谢您:dAndroid视图上的向上和向下动画

+0

我编辑我的答案,并改变了代码一点 –

+0

所有我需要做的是改变的时机,但它的工作原理正如我想要的那样。非常感谢你! :D – Yeol

回答

1

我会做的是动画的看法喜欢你在之前做过,在动画结束时有一种无限循环:

//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); 
        } 
       }); 
    } 
} 

我没有试过尚未但是你可以给它一个去,并告诉我

+0

我不知道Interpolator的用途以及它与Duration有什么不同。 – Yeol

+0

插值器是一种贝塞尔曲线,它将对动画应用不同的效果。 [这里](https://www.youtube.com/watch?v=OMOJxBe9KGg)是一个视频,它会显示各种插值器的结果。这里是[文档](http://developer.android.com/reference/android/view/animation/Interpolator.html),如果你想我看到 –

+0

。谢谢!即时通讯从OnProgressUpdate调用它,但它不移动:< – Yeol

1

下往上:

<?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" /> 

从上至下:

<?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" /> 

代码:

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)); 
       }