为了总结和简化我的问题,我尝试为根视图设置动画效果,然后为子视图设置动画效果。 第一部动画效果不错,但大部分时间停留在原地。动画根视图后的动画子视图
布局:
<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
我只是看到,触摸区域不与视图中移动。
你的min sdk api级别是什么? – sockeqwe