Android旋转动画不停顿
2017-07-19 11:08
453 查看
[java] view
plain copy
package com.example.demoandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button bt;
private Animation an;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.bt);
an = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
an.setInterpolator(new LinearInterpolator());//不停顿
an.setRepeatCount(1);//重复次数
an.setFillAfter(true);//停在最后
an.setDuration(4000);
an.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(MainActivity.this, "开始了", 0).show();
}
@Override
public void onAnimationRepeat(Animation animation) {
Toast.makeText(MainActivity.this, "重复了", 0).show();
}
@Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(MainActivity.this, "结束了", 0).show();
}
});
//动画开始
bt.startAnimation(an);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
bt.clearAnimation();
break;
case MotionEvent.ACTION_UP:
bt.startAnimation(an);
break;
default:
break;
}
return super.onTouchEvent(event);
}
}
plain copy
package com.example.demoandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button bt;
private Animation an;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.bt);
an = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
an.setInterpolator(new LinearInterpolator());//不停顿
an.setRepeatCount(1);//重复次数
an.setFillAfter(true);//停在最后
an.setDuration(4000);
an.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(MainActivity.this, "开始了", 0).show();
}
@Override
public void onAnimationRepeat(Animation animation) {
Toast.makeText(MainActivity.this, "重复了", 0).show();
}
@Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(MainActivity.this, "结束了", 0).show();
}
});
//动画开始
bt.startAnimation(an);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
bt.clearAnimation();
break;
case MotionEvent.ACTION_UP:
bt.startAnimation(an);
break;
default:
break;
}
return super.onTouchEvent(event);
}
}
相关文章推荐
- Android旋转动画不停顿
- Android 旋转动画(RotateAnimation)无限旋转每圈结束停顿问题
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- Android 中 画图与动画旋转效果(中级)
- ANDROID实现圆形图形不断旋转的动画
- Android动画及图片的缩放和旋转
- 实现Android简单动画旋转案例
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- Android 四种简单的动画(淡入淡出、旋转、移动、缩放效果)
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android 3D旋转动画库
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- android自定义动画平移旋转
- android 匀速旋转动画效果
- 如何在Android中实现图片及动画的缩放和旋转
- android 360度图片翻转、旋转动画等待框
- android 中四种补间动画(透明,平移,缩放,旋转)
- Android Property Animation属性动画:rotation旋转(2)
- Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡出效果)