先简单写出各个标签对应的类,方便大家理解: scale —— ScaleAnimation alpha —— AlphaAnimation rotate —— RotateAnimation translate RotateAnimation类对应Rotate标签,SDK文档地址:《RotateAnimation》 Rotate标签所具有的XML属性有: android:fromDegrees 开始旋转的角度位置 (Context context, AttributeSet attrs) 从本地XML文档加载动画,同样,基本不用 RotateAnimation(float fromDegrees, float toDegrees) RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY) RotateAnimation fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) RotateAnimation
,0.5f); //设置动画的时间长度 rotateAnimation.setDuration(2000); //设置重复的类型 rotateAnimation.setRepeatMode(Animation.REVERSE ); //设置重复的次数 rotateAnimation.setRepeatCount(2); //设置是否停留在最终状态 rotateAnimation.setFillAfter(false); // ,0.5f); rotateAnimation.setDuration(2000); rotateAnimation.setRepeatMode(Animation.REVERSE); rotateAnimation.setRepeatCount (2); rotateAnimation.setFillAfter(false); //添加旋转动画 animationSet.addAnimation(rotateAnimation); ScaleAnimation ); rotateAnimation.setRepeatCount(2); rotateAnimation.setFillAfter(false); //
【Android动画九章】-RotateAnimation(旋转动画)和ScaleAnimation(尺寸动画) public abstract class Animation extends Object java.lang.Object ↳ Android.view.animation.Animation Known Direct Subclasses AlphaAnimation, AnimationSet, RotateAnimation , ScaleAnimation, TranslateAnimation 同AlphaAnimation和TranslateAnimation一样,RotateAnimation和ScaleAnimation RotateAnimation 常用构造方法: RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue
EditorGUILayout.EndFadeGroup(); //RotateAnimation var rotateAnimation = animation.rotateAnimation; rotateAnimation.isCustom, () => { rotateAnimation.isCustom = false; EditorUtility.SetDirty(Target); } var rotateAnimation = animation.rotateAnimation; rotateAnimation.isCustom, () => { rotateAnimation.isCustom = false; EditorUtility.SetDirty(Target); }
RotateAnimation实现转动动画: package com.jikexueyuan.rotateanimation; import android.app.Activity; import android.os.Bundle ; public class MainActivity extends Activity { private RotateAnimation ra; @Override ; public class MainActivity extends Activity { private RotateAnimation ra; @Override rotateanimation.setInterpolator(new LinearInterpolator()); rotateanimation.setRepeatCount(ObjectAnimator.INFINITE } public void stop(){ rotateanimation.end(); statics = STOP; } }
度,顺时针转;构造函数:开始度数,结束度数,圆心x(宽度一半),圆心y(高度) 调用RotateAnimation对象的setDuration()方法,设置执行时间,参数:毫秒 调用RotateAnimation rotateAnimation=new RotateAnimation(0, 180, view.getWidth()/2, view.getHeight()); rotateAnimation.setDuration (1000); rotateAnimation.setFillAfter(true); rotateAnimation.setStartOffset(times); static void startAnimIn(RelativeLayout view) { RotateAnimation rotateAnimation=new RotateAnimation (180, 360, view.getWidth()/2, view.getHeight()); rotateAnimation.setDuration(1000); rotateAnimation.setFillAfter
动画可以按先后顺序执行 支持背景色的修改 Animator 的子类 AnimationSet的使用 微卡智享 一般来我说我们在App中常用的都是一些视图动画:包括透明动画(AlphaAnimation)、旋转动画(RotateAnimation //透明度从0至1 AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); //旋转两圈 RotateAnimation rotateAnimation=new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(rotateAnimation
Animation rotateAnimation = null ; int isAnimationState = -1; int time1,time2 = 0; private int = new RotateAnimation((time1),0,Animation.ABSOLUTE,9,Animation.ABSOLUTE,10); rotateAnimation.setDuration = new RotateAnimation(animAngle,0,Animation.ABSOLUTE,9,Animation.ABSOLUTE,10); rotateAnimation.setDuration (0); isAnimationState = 3; break; } rotateAnimation.setFillAfter( true); findViewById(R.id.album_hand).startAnimation(rotateAnimation); }
new AlphaAnimation(1.0f, 0.1f); alphaAnimation.setDuration(3000); RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF , 0.5f); rotateAnimation.setDuration(3000); animationSet.addAnimation (alphaAnimation); animationSet.addAnimation(rotateAnimation); imageView.startAnimation
集合动画AnimationSet 补间动画有四大类:透明度动画AlphaAnimation、旋转动画RotateAnimation、缩放动画ScaleAnimation、平移动画TranslateAnimation 0.5f); rotateAnimation.setDuration(3000); rotateAnimation.setFillAfter(true); } @Override public 0.5f); rotateAnimation2.setDuration(3000); rotateAnimation2.setFillAfter(true); if (animation.equals 0.5f); rotateAnimation.setDuration(3000); rotateAnimation.setFillAfter(true); } @Override public 0.5f); rotateAnimation2.setDuration(3000); rotateAnimation2.setFillAfter(true); if (animation.equals
android.support.v7.app.AppCompatActivity; import android.view.animation.Animation; import android.view.animation.RotateAnimation == Sensor.TYPE_ORIENTATION) { // 获取绕Z轴转过的角度 float degree = event.values[0]; // 创建旋转动画(反向转过degree度) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF // 创建旋转动画(反向转过degree度) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF
package com.itcast.youkumenu; import android.view.View; import android.view.animation.RotateAnimation ra = new RotateAnimation(180, 360, view.getWidth() / 2, view.getHeight()); ra.setDuration(500 ra = new RotateAnimation(0, 180, view.getWidth() / 2, view.getHeight()); ra.setDuration(500) ra = new RotateAnimation(0, 180, view.getWidth() / 2, view.getHeight()); ra.setDuration(500) ra = new RotateAnimation(0, 180, view.getWidth() / 2, view.getHeight()); ra.setDuration(500)
rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //1.2 设置时长 rotateAnimation.setDuration(500); // rotateAnimation.setRepeatCount(1); // rotateAnimation.setRepeatMode(Animation.REVERSE); //1.3 保持动画结束 rotateAnimation.setFillAfter(true); //2. 动画集合 animationSet = new AnimationSet(true); animationSet.addAnimation(rotateAnimation
松开刷新的状态 private final int REFRESHING = 2;//正在刷新的状态 private int currentState = PULL_REFRESH; private RotateAnimation addHeaderView(headerView); } /** * 初始化旋转动画 */ private void initRotateAnimation() { upAnimation = new RotateAnimation (0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); upAnimation.setDuration(300); upAnimation.setFillAfter(true); downAnimation = new RotateAnimation (-180, -360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f)
android.view.ViewGroup; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation animation; private RotateAnimation reverseAnimation; // 用于保证startY的值在一个完整的touch事件中只被记录一次 private addHeaderView(headView, null, false); setOnScrollListener(this); animation = new RotateAnimation (0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); (-180, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
iView.startAnimation(ta); } 位移动画有两种构造方法,具体还需自己尝试尝试 d:旋转动画 public void RotateAnimation (View v) { //旋转开始角度和结束角度 //ra = new RotateAnimation(0, -15); //ra = new RotateAnimation (20, 360, iView.getWidth()/2, iView.getHeight()/2); ra = new RotateAnimation(0, 90, Animation.RELATIVE_TO_SELF
event.sensor.getType() == Sensor.TYPE_ORIENTATION){ float degree = - event.values[0]; RotateAnimation rotateAnimation = new RotateAnimation(mDegress, degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF , 0.5f); rotateAnimation.setDuration(100); mIvSensor.startAnimation(rotateAnimation
Animation(动画)有两种分类:补间动画(Tween)和帧动画(Frame) 补间动画主要有以下几种: 旋转(RotateAnimation) 平移(TranslateAnimation) 拉伸 rotateAnimation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF , 0.5f); rotateAnimation.setDuration(5000); // 循环播放,参数循环的次数,会在setDuration的时间中循环完,循环为0~180,0~-180算一次 CycleInterpolator (rotateAnimation); /** * 动画集合 */ // 方法一: Animation set = AnimationUtils.loadAnimation(this, R.anim.set 所以动画都执行同一个变速器即set设置的变速器,false执行各自的变速器 AnimationSet set2 = new AnimationSet(false); set2.addAnimation(rotateAnimation
private ImageView arrowImageView;// 箭头的图片 private ProgressBar progressBar;// 刷新进度 private RotateAnimation animation;// 箭头向下动画 private RotateAnimation reverseAnimation;// 逆向箭头动画 private boolean isRecored 那就是可以在顶部和底部添加自定义的视图 setOnScrollListener(this); // 箭头向下动画 animation = new RotateAnimation (0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF (-180, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF
Java Code代码中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation scale ScaleAnimation 一种是frame by frame(画面转换动画) XML中 JavaCode translate TranslateAnimation rotate RotateAnimation RotateAnimation RotateAnimation类对象定义 private RotateAnimation myAnimation_Rotate; RotateAnimation类对象构造 RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue //第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置 myAnimation_Rotate = new RotateAnimation