android 旋转动画
2015-12-25 13:54
417 查看
1.java代码
int pivotType = Animation.RELATIVE_TO_SELF; // 相对于自己
float pivotX = .5f; // 取自身区域在X轴上的中心点
float pivotY = .5f; // 取自身区域在Y轴上的中心点
rotateAnimation = new RotateAnimation(firstFromRoate, lastdegreen,
pivotType, pivotX, pivotType, pivotY); // 围绕自身的中心点进行旋转
firstFromRoate=lastdegreen;
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(0);
rotateAnimation.setFillAfter(true);
iv_zhizhen.startAnimation(rotateAnimation);
2.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:duration="500"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%" />
</set>
含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。
Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);
LinearInterpolator lin = new LinearInterpolator(); //匀速效果
operatingAnim.setInterpolator(lin);
setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。
if (operatingAnim != null) {
infoOperatingIV.startAnimation(operatingAnim);
}
完成时
infoOperatingIV.clearAnimation();
int pivotType = Animation.RELATIVE_TO_SELF; // 相对于自己
float pivotX = .5f; // 取自身区域在X轴上的中心点
float pivotY = .5f; // 取自身区域在Y轴上的中心点
rotateAnimation = new RotateAnimation(firstFromRoate, lastdegreen,
pivotType, pivotX, pivotType, pivotY); // 围绕自身的中心点进行旋转
firstFromRoate=lastdegreen;
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(0);
rotateAnimation.setFillAfter(true);
iv_zhizhen.startAnimation(rotateAnimation);
2.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:duration="500"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%" />
</set>
含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。
Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);
LinearInterpolator lin = new LinearInterpolator(); //匀速效果
operatingAnim.setInterpolator(lin);
setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。
if (operatingAnim != null) {
infoOperatingIV.startAnimation(operatingAnim);
}
完成时
infoOperatingIV.clearAnimation();
相关文章推荐
- RxJava与RxAndroid 接收消息通知
- android studio 的奇葩环境问题
- Android 中的自定义开关按钮
- 【Android】Android Studio 快速打开Github上的Demo
- Android Service在bindService不能触发onServiceConnected方法
- Debug的方式
- Android进程间通信之Messenger浅析
- 浅谈android 视频播放VideoView
- 如何调用Android隐藏API
- Android之查看外部依赖jar的源代码_android private libralies does not allow modifications to source
- android AsyncTask介绍
- android 手机拍照选择本地图片
- android 界面中的各种布局
- Android通过webservice连接SQLServer 详细教程(数据库+服务器+客户端)
- Android之string.xml 使用总结
- 安卓源码--修改设置语言选择列表
- Android Volley获取本地缓存
- android获取手机配置具体代码
- Android开发实现TextView显示丰富的文本
- Android适配方案小结(一)