0
我尝试在Android中制作旋转游戏的游戏。 我发现很难以正确的方式旋转圆圈。 我很想帮助如何旋转圆圈并停止它,以便每次都得到不同的结果。 目前它已经确定了一定的时间并返回到开头。 如果我通过这个msmallWheelBack.clearAnimation()停在它的中间,它将返回到一轮的开始。 非常感谢您的帮助。轮盘赌动漫旋转得到它停止的位置Android
在我的代码:
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
mframeWheelBig.startAnimation(animation);
的动画XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="2500"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360"
android:fromDegrees="0"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"/>
</set>
就像我说的,这是我如何停止动画
mframeWheelBig.clearAnimation();
的一个大问题是,它在阻止它开始 – gal
动画停止在它开始的地方的地方,因为你所定义的360度,这正好是一个完整的转身结束位置。通过为结束位置提供随机值,这不会发生。 – Ridcully
int MIN_TURNS = 3; int MORE_TURNS = 3; float toDegrees = 360 * MIN_TURNS +(float)Math.random()* 360f * MORE_TURNS; Log.i(“toDegrees”,“”+ toDegrees);动画动画= new RotateAnimation(0,toDegrees,200,200); animation.setInterpolator(new AccelerateDecelerateInterpolator()); animation.setDuration(1000); animation.setFillAfter(true); – gal