android 动画变换,Android-Animation动画(变换动画,帧动画,布局动画)

1.回顾

上篇学习了 封装 一般常用的Adpater 为jar ,方便使用;

2. 重点

(1)变换动画(TweenAnimation)

(2)帧动画   (FrameAnimation)

(3)布局动画 (LayoutAnimation)

3.变换动画

3.1 四个基本的变换

Alpha :渐变;   Scale : 渐变尺寸;   Translate :位置移动动画;  Rotate:旋转动画;

3.2 常用属性:

(1)  Duration :动画时间;

(2)fillAfter :为true 动画转换为 动画结束后应用;

(3)fillBefore :true 动画转换 直接被 应用;

(4)interpolator :动画插入器(加速,减速插入器);

(5)repeatCount  : 动画重复次数;

(6)repateMode   :顺序重复 、倒叙重复;

(7)startOffset  : 动画之间的时间间隔;

3.3 实现方式:

配置文件:alpha , scale ,translate ,rotate ;

代码实现:AlphaAnimation ,ScaleAnimation ,TranslateAnimation,RotateAnimation;

3.4 Alpha 实现

(1)代码实现

Animation animation = new AlphaAnimation(0.1f, 1.0f);

animation.setDuration(5000);

imageview1.startAnimation(animation);

(2)布局实现

android:duration="1000"

android:fromAlpha="0.1"

android:toAlpha="1.0"

/>

加载:

Animation animation2 = AnimationUtils.loadAnimation(

MainActivity.this, R.anim.alpha);

imageview1.startAnimation(animation2);

3.5 Scale 缩放

(1)代码实现

/**

* 参数:

* 0.0~1.0

* float fromX :x开始比例

* float toX :x结束比例

* float fromY :y开始比例

* float toY, :y结束比例

* int pivotXType :Animation.RELATIVE_TO_SELF 相对与自己缩放

* float pivotXValue :x缩放的位置 0.0~1.0 ;0.5为 中心

* int pivotYType :Animation.RELATIVE_TO_SELF 相对与自己缩放

* float pivotYValue :y缩放的位置 0.0~1.0 ;0.5为 中心

*

*/

Animation animation = new ScaleAnimation(1.0f, 0.3f, 1.0f, 0.3f,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

animation.setDuration(1000);

//缩放结束后,保持为改比例

animation.setFillAfter(true);

imageview1.startAnimation(animation);

(2)布局实现

android:duration="2000"

android:fillAfter="false"

android:fromXScale="0.0"

android:fromYScale="0.0"

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:pivotX="50%"

android:pivotY="50%"

android:toXScale="1.0"

android:toYScale="1.0" />

调用:

Animation anim= AnimationUtils.loadAnimation(this, R.anim.scale);

image.startAnimation(anim);

3.6 Translate 移动

(1)代码实现

/**

* 参数:

* int fromXType ,x初始相对位置

* float fromXValue, x 初始位置

* int toXType, x 目标相对位置

* float toXValue, x目标位置

* int fromYType, y 初始相对位置

* float fromYValue, y 初始位置

* int toYType, y目标相对位置

* float toYValue y目标位置

*

* 下面实现 平移效果

*

*/

Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,

0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF, 0.0f);

animation.setDuration(1000);

imageview1.startAnimation(animation);

(2)布局实现

android:duration="1000"

android:fromXDelta="10"

android:fromYDelta="10"

android:toXDelta="100"

android:toYDelta="100" />

3.7 Rotate 旋转效果

(1)代码实现

/**

* 参数:

* float fromDegrees, 开始角度

* float toDegrees, 旋转的角度

* int pivotXType, x相对属性 Animation.RELATIVE_TO_SELF

* float pivotXValue, 旋转中心 x

* int pivotYType, y相对属性 Animation.RELATIVE_TO_SELF

* float pivotYValue 旋转中心 y

*

* 旋转180度

*/

Animation animation = new RotateAnimation(0.0f, 180.0f,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

animation.setDuration(2000);

animation.setFillAfter(true);

imageview1.startAnimation(animation);

(2)布局实现

android:duration="1000"

android:fromDegrees="0"

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:pivotX="50%"

android:pivotY="50%"

android:toDegrees="+360" />

调用:

Animation anim= AnimationUtils.loadAnimation(this, R.anim.rotate);

image.startAnimation(anim);

4.帧动画 FrameAnimation

(1)实现布局 animation-list

android:drawable="@drawable/one"

android:duration="500"/>

android:drawable="@drawable/two"

android:duration="500"/>

android:drawable="@drawable/three"

android:duration="500"/>

android:drawable="@drawable/four"

android:duration="500"/>

android:drawable="@drawable/five"

android:duration="500"/>

android:drawable="@drawable/six"

android:duration="500"/>

(2)加载

ImageView加载 实现动画;

image.setImageResource(R.drawable.anim_list);

5. 布局动画

(1) 实现LayoutAnimationController 实现加载动画;

LayoutAnimationController lac=new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.zoom_in));

lac.setOrder(LayoutAnimationController.ORDER_NORMAL);

listView.setLayoutAnimation(lac);

(2)动画实现 渐进进入

android:interpolator="@android:anim/decelerate_interpolator" >

android:duration="1000"

android:fromXScale="0.1"

android:fromYScale="0.1"

android:pivotX="50%"

android:pivotY="50%"

android:toXScale="1.0"

android:toYScale="1.0" />

android:duration="1000"

android:fromAlpha="0"

android:toAlpha="1.0" />

(3)动画实现 渐进渐出

android:interpolator="@android:anim/decelerate_interpolator"

android:zAdjustment="top" >

android:duration="@android:integer/config_mediumAnimTime"

android:fromXScale="1.0"

android:fromYScale="1.0"

android:pivotX="50%p"

android:pivotY="50%p"

android:toXScale="0.1"

android:toYScale="0.1" />

android:duration="@android:integer/config_mediumAnimTime"

android:fromAlpha="1.0"

android:toAlpha="0" />

6. Activity 切换动画

使用 overridePendingTransition实现加载动画;

实例:

Intent intent=new Intent(MainActivity.this,MainActivity2.class);

startActivity(intent);

overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out);

7.总结

这里仅仅是最基本的动画,更复杂的动画效果,需要组合完成;下篇学习Android的属性动画;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值