2014-12-24 26 views
0

爲了總結和簡化我的問題,我嘗試爲根視圖設置動畫效果,然後爲子視圖設置動畫效果。 第一部動畫效果不錯,但大部分時間停留在原地。動畫根視圖後的動畫子視圖

佈局:

<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</FrameLayout> 

示例代碼:

TranslateAnimation translateAnimation=new TranslateAnimation(0, 0, 0, 300); 
    translateAnimation.setDuration(2000); 
    translateAnimation.setFillAfter(true); 
    translateAnimation.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
      rotateAnimation.setInterpolator(new LinearInterpolator()); 
      rotateAnimation.setDuration(750); 
      rotateAnimation.setRepeatCount(Animation.INFINITE); 
      rotateAnimation.setRepeatMode(Animation.RESTART); 

      imageView.startAnimation(rotateAnimation); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { } 
    }); 

    container.startAnimation(translateAnimation); 

有時我看到傾斜的ImageView。或旋轉,但只是一部分。 有人知道發生了什麼嗎?

我也嘗試過使用setFilterAfter(false)並在onAnimationEnd上用setTranslationY()移動我的容器,但是一些框架是可見的。

謝謝。

EDIT

在真實情況下,TranslateAnimation是內部ViewPager的片段的ViewPager(到QuickReturn圖案)和RotateAnimation(到PullToRefresh圖案)。 所以動畫不一定像上面所做的那樣是連續的,並且強烈分離(ViewPager/Fragment)。

EDIT2

我只是看到,觸摸區域不與視圖中移動。

+0

你的min sdk api級別是什麼? – sockeqwe

回答

0

我並不是說這是去上班,但讓我們這個給一試:

讓我們分開的動畫,而不是把它們連與animationListener;相反,我們使用ObjectAnimator和AnimationSet來幫助我們爲我們排序動畫。

ObjectAnimator translateContainer = ObjectAnimator.ofFloat(container, "translationY", 300); 
translateContainer.setDuration(2000); 

ObjectAnimator rotateImage = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f); 
rotateImage.setDuration(750); 

AnimatorSet animSet = new AnimatorSet(); 
animSet.playSequentially(translateContainer, rotateImage); 
animSet.start(); 
+0

我編輯了我以前的帖子來描述實例用例。在這些情況下,我不能使用AnimatorSet。 – Wicowyn