2014-12-24 68 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