2017-02-27 83 views
1

我试图删除显示一个视图,但看起来像旋转卡的方式。
下面没有旋转视图,但不是我想要做的。连锁动画的旋转,直到视图不在窗口

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <rotate 
     android:duration="1500" 
     android:fromDegrees="0" 
     android:pivotX="100%" 
     android:pivotY="50%" 
     android:startOffset="0" 
     android:toDegrees="220" /> 
</set> 

什么我以后是不是旋转本身围绕一个固定的中心,但类似投掷卡的议案。
我该怎么做?

更新
我想这个答案之后,从@loadedion但不工作:

ObjectAnimator rotateAnimation = ObjectAnimator.ofFloat(rootView, "rotation", 0.0f, 360f); 
rotateAnimation.setDuration(5000); 

ObjectAnimator throwAnimation = ObjectAnimator.ofFloat(rootView, "x", rootView.getX(), rootView.getX() + 200); 
throwAnimation.setInterpolator(new AccelerateInterpolator()); 
     throwAnimation.setDuration(3000); 
ObjectAnimator throwAnimation2 = ObjectAnimator.ofFloat(rootView, "y", rootView.getY(), rootView.getY() + 200);  
throwAnimation.setInterpolator(new AccelerateInterpolator()); 
throwAnimation.setDuration(3000); 
AnimatorSet cardThrowAnimations = new AnimatorSet(); 
cardThrowAnimations.playSequentially(rotateAnimation, throwAnimation, throwAnimation2); 
     cardThrowAnimations.start(); 
+0

我相信'playSequentially'会等到每个动画在开始下一个之前完成,所以看起来像这样会导致卡真正缓慢旋转5秒,然后稍稍向右移动3秒,然后稍微向下移动3秒conds。那是你所看到的吗?使用'playTogether'可以同时运行所有的动画。 – loadedion

回答

0

如果你想有一个视图旋转,你必须动画应用到它。

ObjectAnimator rotateAnimation = ObjectAnimator.ofFloat(targetView, "rotation", 0.0f, 360f); 
rotateAnimation.setRepeatCount(ObjectAnimator.INFINITE); 
rotateAnimation.setRepeatMode(ObjectAnimator.RESTART); 
rotateAnimation.setInterpolator(new LinearInterpolator()); 
rotateAnimation.setDuration(DURATION_ROTATION); 

如果你希望它滑出像扔卡,而它的旋转,你可以创建另一个ObjectAnimator来设置它的x位置。

ObjectAnimator throwAnimation = ObjectAnimator.ofFloat(targetView, "x", targetView.getX(), targetView.getX() + 500); // move 500 pixels to the right 
throwAnimation.setInterpolator(new AccelerateInterpolator()); 
throwAnimation.setDuration(DURATION_THROW); 

,然后启动动画

rotateAnimation.start(); 
throwAnimation.start(); 

另外,您也可以将它们组合起来在AnimatorSet开始在一起:

AnimatorSet cardThrowAnimations = new AnimatorSet(); 
cardThrowAnimations.playTogether(rotateAnimation, throwAnimation); 
cardThrowAnimations.start(); 
+0

我在想我可能需要使用2个动画,但我怎样才能找出第二个动画的X,Y位置? – Jim

+0

在第一次旋转结束后,START_X_POSITION AND START_Y_POSITION应该由视图的新位置确定?怎么样? – Jim

+0

@Jim你可以在你的布局中将卡片视图定位在动画的开始位置,这样你就可以通过'targetPosition.getX()'和'targetPosition.getY()'获得开始的x,y(确保轮询视图之后的x,y位置已经创建) – loadedion