Android动画之RotateAnimation使用
16lz
2021-01-23
- RotateAnimation:旋转动画,顾名思义,使用该动画,view能产生旋转效果
比如QQ音乐播放状态的专辑
- 看一下xml文件:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:duration="5000" android:fillAfter="true" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatMode="restart" android:repeatCount="infinite" android:toDegrees="360" />set>
属性解释:
android:fromDegrees=”0” //从多少度开始旋转
android:toDegrees=”360” //旋转到多少度结束
android:pivotX=”50%” // 相对x轴起始位置开始执行动画,取值(0-100%)
android:pivotY=”50%” // 相对y轴起始位置开始执行动画,取值(0-100%)
android:repeatMode=”restart” //重复模式为:重复动画
android:repeatCount=”infinite”//重复次数:无限次
- Java代码调用xml文件:
/** * 旋转动画 * * @param context * @param view 目标view */ public static void startRotateAnim(Context context, View view) { Animation animation = AnimationUtils.loadAnimation(context, R.anim.anim_rotate); animation.setInterpolator(new LinearInterpolator()); if (view != null) view.startAnimation(animation); }
- 效果如下:
- 纯Java代码动画:
public static void animRotate(View view){ RotateAnimation animation = new RotateAnimation(0,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animation.setDuration(5000); animation.setFillAfter(true); animation.setInterpolator(new LinearInterpolator()); animation.setRepeatMode(Animation.RESTART); animation.setRepeatCount(Animation.INFINITE); if (view != null) view.startAnimation(animation); }
更多相关文章
- 安卓文字过长,跑马灯文字滚动效果
- Android中保存并设置ListView位置
- Android 实现多行文本跑马灯效果
- Android viewpager 实现画廊效果 左右可见部分子view
- Android 开机动画
- android 按钮水波纹效果【背景色】
- Android消息处理机制实现同步效果
- Android实现网易新闻客户端首页效果