1.Tweened Animation 渐变动画
该类提供了 旋转,移动,淡入淡出,缩放
2.Frame-by-Frame Animation
Tweened Animation:
1.Alpha:淡入淡出效果
2.Scale:缩放效果
3.Rotate:旋转效果
4.Translate:移动效果
Tweened Animation 渐变动画
AlphaAmination:淡入淡出
Public Constructors:
Constructor used when an AlphaAnimation is loaded from a resource.
AlphaAnimation(float fromAlpha,float toAlpha)
Constructor to use when building an AlphaAnimation from code
Public Methods:
willChangeBounds() :返回值boolean
Indicates whether or not this animation will affect the bounds of the animated view.
willChangeTransformationMatrix() :返回值 boolean
Indicates whether or not this animation will affect the transformation matrix.
Protected Methods
applyTransformation(float interpolatedTime,Transformationt) 无返回值
Changes the alpha property of the supplied
Transformation
使用
// AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
// alphaAnimation.setDuration(1000);
// arg0.startAnimation(alphaAnimation);
布局形式使用该效果:
arg0.startAnimation(AnimationUtils.loadAnimation(MainActivity.this,R.anim.alpha));
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000">
</alpha>
RotateAnimation:旋转动画效果
实现控件的旋转效果;
Public Constructors:
Constructor used when a RotateAnimation is loaded from a resource.
RotateAnimation(float fromDegrees,float toDegrees) 直接构造RotateAnimation对象 中心点为默认的控件de(fromDegrees,toDegrees) 做旋转
Constructor to use when building a RotateAnimation from code.
函数 以自定义的(pivotX,pivotY)做旋转
Constructor to use when building a RotateAnimation from code
RotateAnimation(float fromDegrees,int pivotXType,float pivotXValue,int pivotYType,float pivotYValue) 直接构造 RotateAnimation 以某一个事物为参考 做旋转
Constructor to use when building a RotateAnimation from code
Public Methods
initialize(int width,int height,int parentWidth,int parentHeight) 无返回值
Initialize this animation with the dimensions of the object being animated as well as the objects parents.
将初始化动画组件及其父容器的宽高;通常亦可进行另外的初始化工作
Ptotected Methods
第一个参数为动画的进度时间值,取值范围为[0.0f,1.0f],第二个参数Transformation记录着动画某一帧中变形的原始数据。该方法在动画的每一帧显示过程中都会被调用。
代码实现效果:
RotateAnimation rotateAnimation = new RotateAnimation(0,360); 以默认值为控件左上角为中心点 做旋转
RotateAnimation rotateAnimation = new RotateAnimation(0,360,100,200);//以我们自定义的一个点 作为中心点
RotateAnimation rotateAnimation = new RotateAnimation(0,Animation.RELATIVE_TO_SELF,0.5f,0.5f);
rotateAnimation.setDuration(3000);
arg0.startAnimation(rotateAnimation);
布局文件实现效果:
arg0.startAnimation(AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate));
布局文件: 注意属性:android:pivotX android:pivotY 如果去百分比则以自身作为参考点 以数值则不是
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="3000"
android:pivotX="50%"
android:pivotY="50%">
</rotate
TranslateAnimation:移动动画效果
实现控件的移动效果;
Public Constructors
Constructor used when a TranslateAnimation is loaded from a resource.
TranslateAnimation(float fromXDelta,float toXDelta,float fromYDelta,float toYDelta) 从给定的数值
Constructor to use when building a TranslateAnimation from code
TranslateAnimation(int fromXType,float fromXValue,int toXType,float toXValue,int fromYType,float fromYValue,int toYType,float toYValue) 相对于某一个控件 把他当做参考系
Constructor to use when building a TranslateAnimation from code
Public Methods:
Protected Methods
Helper for getTransformation.
代码实现:
TranslateAnimation translateAnimation = new TranslateAnimation(0,200,400);//相对于自身的
translateAnimation.setDuration(3000);
arg0.startAnimation(translateAnimation);
布局文件实现:
arg0.startAnimation(AnimationUtils.loadAnimation(MainActivity.this,R.anim.tranlate));
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<translate
android:fromXDelta="0"
android:toXDelta="200"
android:fromYDelta="0"
android:toYDelta="200"
android:duration="3000" xmlns:android="http://schemas.android.com/apk/res/android">
</translate>
ScaleAnimation 缩放效果
缩放动画效果:
Public Constructions:
ScaleAnimation(
AttributeSetattrs) :从资源中创建对象
Constructor used when a ScaleAnimation is loaded from a resource.
ScaleAnimation(float fromX,float toX,float fromY,float toY) 各个参数都是相对于控件的倍数 默认从控件的左上角(0,0)开始缩放 前两个参数为X轴方向 后两个参数为Y轴方向
Constructor to use when building a ScaleAnimation from code
ScaleAnimation(float fromX,float toY,float pivotY) 各个参数都是相对于控件的倍数 从(pivotX,pivotY)开始缩放
Constructor to use when building a ScaleAnimation from code
Public Methods;
initialize(int width,247)">
Initialize this animation with the dimensions of the object being animated as well as the objects parents.
Protected Methods:
代码实现:
ScaleAnimation scaleAnimation = new ScaleAnimation(0,(float)1.5,(float)1.5);////默认从左上角缩放
ScaleAnimation scaleAnimation = new ScaleAnimation(0,50,50);
ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0.5f);
scaleAnimation.setDuration(3000);
arg0.startAnimation(scaleAnimation);
布局实现:
arg0.startAnimation(AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale));
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:duration="3000" >
</scale>
TranslateAnimation 移动效果
Public Constructions;
TranslateAnimation(float fromXDelta,float toYDelta) 在X Y轴相对于控件的当前位置进行偏移
Helper for getTransformation.
代码实现:
TranslateAnimation translateAnimation = new TranslateAnimation(0,0);
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,50f,0f);
translateAnimation.setDuration(3000);
arg0.startAnimation(translateAnimation);
如果要是动画可以循环执行那可以设置 setRepeatCount(Animation.INFINITE)
他们也有事件的监听 需要实现AnimationListener接口
onAnimationStart onAnimationEnd onAnimationRepeat
动画的混合效果:
就是使用一个容器将 这些效果装载起来 然后一起给控件使用
创建一个类继承Animation 然后去重写initialize,applyTransformation两个方法
其中initialize:初始化
applyTransformation:实现效果