Android之AnimationSet
来源:互联网 发布:淘宝小号怎么查询信誉 编辑:程序博客网 时间:2024/06/07 22:15
1、AnimationSet用来做什么的?
AnimationSet类是Android系统中的动画集合类,用于控制View对象进行多个动作的组合,该类继承于Animation类。
2、AnimationSet有哪些公有方法?
Add a child animation to this animation set.添加动画到AnimationSet
The duration hint of an animation set is the maximum of the duration hints of all of its component animations.
The duration of an AnimationSet is defined to be the duration of the longest child animation.
When this animation should start.
The transformation of an animation set is the concatenation of all of its component animations.
Initialize this animation with the dimensions of the object being animated as well as the objects parents.
Reset the initialization state of this animation.
Ensure that the duration that this animation will run is not longer than durationMillis.确保该动画将运行时间不超过durationmillis
How much to scale the duration by.当前时间缩放scale
Sets the duration of every child animation.设置每个动画持续时间
If fillAfter is true, the transformation that this animation performed will persist when it is finished.如果fillAfter是trure,保持结束时动画状态
If fillBefore is true, this animation will apply its transformation before the start time of the animation.
Defines what this animation should do when it reaches the end.定义这个动画应该做什么,当它到达结束。
When this animation should start relative to the start time.
Sets the start time of this animation and all child animations
Indicates whether or not this animation will affect the bounds of the animated view.动画是否影响指定的视图范围
Indicates whether or not this animation will affect the transformation matrix.动画是否影响转换矩阵
RESTART
or REVERSE
Demo:
package com.lxm.animationset;import android.util.Log;/** * Created by Administrator on 2015/9/19. */public class MyLog { private static boolean flag = true; public static void d(Object object){ if(flag) { Log.d("myLog", object == null ? null : object.toString()); } }}
<span style="font-family: Arial, Helvetica, sans-serif;">package com.lxm.animationset;</span>
import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.widget.Button;import android.widget.ImageView;import java.util.List;public class MainActivity extends Activity implements View.OnClickListener{ private ImageView mTv; private Button mStartBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTv = (ImageView) findViewById(R.id.id_tv); mStartBtn = (Button) findViewById(R.id.id_startAnimation); mStartBtn.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.id_startAnimation: AnimationSet anim = new AnimationSet(true); AlphaAnimation a=new AlphaAnimation(1f,0f); RotateAnimation ra = new RotateAnimation(0,680, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); a.setDuration(3000); anim.addAnimation(a); anim.addAnimation(ra); anim.setDuration(3000); anim.setStartOffset(1000);// anim.setFillAfter(false); anim.setFillBefore(false); a.setRepeatCount(2); ra.setRepeatCount(2); //动画结束之后,反向执行动画 ra.setRepeatMode(Animation.REVERSE); long maxTime = anim.computeDurationHint(); long aDuration = a.getDuration(); List<Animation> animationList = anim.getAnimations(); long startTime = anim.getStartTime(); mTv.startAnimation(anim); MyLog.d("最大的持续时间" + maxTime); MyLog.d("透明动画持续"+aDuration); MyLog.d("动画开始时间"+startTime); for (int i=0;i<animationList.size();i++){ MyLog.d("动画"+animationList.get(i).getClass().getName()); } break; } }}获取最大的持续时间,透明动画持续时间,动画开始时间,获取动画对象。
为什么最大的持续时间是9000?
因为重复两次,每次的时间是3000,加上第一次,所以(1+2)*3000=9000
为什么动画开始时间是-1?
因为AlphaAnimation,RotateAnimation的开始时间都没有设置,取不到,所以显示的是-1。可以看一下getStartTime源码,
@Override public long getStartTime() { long startTime = Long.MAX_VALUE; final int count = mAnimations.size(); final ArrayList<Animation> animations = mAnimations; for (int i = 0; i < count; i++) { Animation a = animations.get(i); startTime = Math.min(startTime, a.getStartTime()); } return startTime; }如果加上这两行代码
a.setStartTime(1000);ra.setStartTime(2000);结果如图:
为什么动画开始时间是1000?
看了getStartTime源码会知道,因为返回的是List<Animation>中最小开始时间
0 0
- Android之AnimationSet
- android AnimationSet
- android animationset
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- Android动画之Interpolator和AnimationSet(三)
- android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet
- Android动画之Interpolator和AnimationSet(三)
- Android动画 之 Tween Animation(AnimationSet 混合动画)
- Android中的AnimationSet使用
- android AnimationSet 使用
- Android中的AnimationSet使用
- android AnimationSet小结
- 年月日关联 判断平年闰年月份天数判断 放入Spinner 菜鸟
- PHP防止SQL注入详解及防范
- 3.3 difflib--比较不同序列之间差异库
- Odoo(OpenERP)应用实践: 使用db-filter参数实现通过域名指定访问哪个数据库
- Python 标准库——operator
- Android之AnimationSet
- LBS JAVA Spring mongoDB
- FlatBuffers小试
- springMVC工作原理
- ubuntu安装deb文件时,缺少的依赖的下载网址
- python的numpy、scipy、pandas、matplotlib、pip库下载
- 未来智能设备不再以视觉展现为主!
- 改变unity场景的图片比例保存到xml当中
- 01机房可行性研究报告