我试图移除显示视图,但是看起来像是在旋转卡片 以下是旋转视图,但不是我想要做的。
<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 :(得分: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();