本文介绍了缓动效果在android的旋转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的动画纺轮轮盘游戏,对于我想轮被旋像晕头转向(例如车轮打滑速度应该慢慢开始迅速然后慢慢停止)
I am working on animation for spinning wheel for roulette game, for that i want wheel to be spin like real spin(e.g. wheel spin speed should start slowly then speedily and stop slowly)
我知道这是我的应用基础旋转的动画,下面是我的动画XML文件code:
I know basic rotate animation which i applied, below is my animation XML file code :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="200"
android:repeatMode="restart"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
和经济活动:
public class RouletteActivity extends Activity {
Button button_spin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_roulette);
button_spin = (Button)findViewById(R.id.btn_spin);
button_spin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
StartLoading();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
StopLoading();
}
}, 5000);
}
});
}
public void StartLoading() {
ImageView img_wheel = (ImageView) this.findViewById(R.id.imageView1);
img_wheel.setImageDrawable(getResources().getDrawable(R.drawable.wheel));
Animation rotateLoading = AnimationUtils.loadAnimation(this, R.anim.rotate);
img_wheel.clearAnimation();
img_wheel.setAnimation(rotateLoading);
}
public void StopLoading() {
ImageView img_wheel = (ImageView) this.findViewById(R.id.imageView1);
if (img_wheel.getAnimation() != null)
{
img_wheel.clearAnimation();
img_wheel.setImageDrawable(getResources().getDrawable(R.drawable.wheel));
}
}
请帮我实现动画像我想要的东西,谢谢。
Please help me to achieve animation like what i want, thank you.
推荐答案
您可以通过将它的。结果
在 AccelerateDecelerateInterpolator 似乎是最好的位置。
You can modify the behavior of your animation by applying it a Interpolator.
The AccelerateDecelerateInterpolator seems to be the best here.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="200"
android:repeatMode="restart"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
</set>
或者更简单的:
yourView.animate().rotation(value).setInterpolator(new AccelerateDecelerateInterpolator()).start();
这篇关于缓动效果在android的旋转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!