首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android之animation(2)animationset、interpolator

2012-06-28 
android之animation(二)animationset、interpolator一:animationset:他是一个animation的一个子类,实际上是

android之animation(二)animationset、interpolator

一:

animationset:

他是一个animation的一个子类,实际上是animation的一个集合。他将animation放到一个list集合中。需要对animation的基本设置可以通过animationset来设置。如果需要对一个控件进行多种动画设置,可以采用animationset。

代码:

?

              //创建一个animationsetAnimationSet animationset = new AnimationSet(true);//创建一个alphaanimationAnimation alphaanimation = AnimationUtils.loadAnimation(Animation1Activity.this,R.anim.alpha);ScaleAnimation scaleanimation  = new ScaleAnimation(1f, 0f, 1f, 0f, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF);//设置动画时间animationset.addAnimation(alphaanimation);animationset.addAnimation(scaleanimation);animationset.setDuration(2000);animationset.setStartOffset(2000);imageview.setAnimation(animationset);

?

?

代码说明:我们运用AnimationUtils加载一个xml中的alphaanimation,然后向上转系为Animation,然后再新建一个

scaleanimation,然后通过animationset将这两个动画添加到一起,然后绑定在一个控件上面。

可以通过只设置animationset来对动画共有属性进行配置。

?

****************************************************************************************************

?

二:

interpolator:动画变化的速率。

在animations框架当下定义了以下几种interpolator:

AccelerateDecelerateInterpolator ?在动画开始与结束的地方速率改变比较慢,在中间的时候较快。
AccelerateInterpolator ?在动画开始的时候改变较慢,然后开始加速。
CycleInterpolator ?动画循环播放特定次数,速率改变沿着正弦曲线。
DecelerateInterpolator ? 在动画开始的时候叫慢,然后开始减速。
LinearInterpolator ? 动画以均匀速率改变。

?

这个是在xml中进行设置:

?

<?xml version="1.0" encoding="utf-8"?><set  xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"android:shareInterpolator="true"><alpha android:fromAlpha="1"android:toAlpha="0"android:duration="1000"/><rotate android:fromDegrees="0"android:toDegrees="180"android:pivotX="100%"android:pivotY="100%"android:duration="1000"/></set>
?

代码解释:基本语法已经在上集讲过了,现在看上面的那个<set 标签,表示的就是animationset,指一系列的animation,下面可以加上多个animation。

android:interpolator这个就是设置动画改变速率,下面的那个android:shareInterpolator指下面的animation是否共享上面的动画改变速率,如果不共享,可以在下面的animation中单独设置。

热点排行