AnimationSet 的使用方法
AnimationSet 是 Animation 的子类,一个AnimationSet 包含了一系列的Animation,针对AnimationSet 设置一些Animation 的常见属性比如startOffset,duration 等等。设置之后的属性会控制AnimationSet 下的所有Animation。
在Java 文件中。
Interpolator 的使用方法
Interpolator 定义了动画变化的速率,在Animation 框架中定义了以下几种Interpolator :
AccelerateDecelerateInterpolator:在动画开始与结束的地方速率改变比较慢,在中间加速;
AccelerateInterpolator:在动画开始的地方速率改变比较慢,然后加速;
CycleInterpolator:动画循环播放特定次数,速率改变沿着正弦曲线;
DecelerateInterpolator:在动画开始的地方速率改变比较慢,然后开始减速;
LinearInterpolator:在动画的以均匀的速率改变。
在Java 文件中对imagView 调用setBackgroundResouce 方法即可。
AnimationSet 是 Animation 的子类,一个AnimationSet 包含了一系列的Animation,针对AnimationSet 设置一些Animation 的常见属性比如startOffset,duration 等等。设置之后的属性会控制AnimationSet 下的所有Animation。
在res 文件夹下创建anim 文件夹,创建xml 文件,此时一个xml 文件可放多个标签。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="2000"
android:duration="5000"/>
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%p"
android:pivotY="50%p"
android:duration="5000"/>
</set>
在Java 文件中。
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.doubleset);
imageView.startAnimation(animation);
}
}
Interpolator 的使用方法
Interpolator 定义了动画变化的速率,在Animation 框架中定义了以下几种Interpolator :
AccelerateDecelerateInterpolator:在动画开始与结束的地方速率改变比较慢,在中间加速;
AccelerateInterpolator:在动画开始的地方速率改变比较慢,然后加速;
CycleInterpolator:动画循环播放特定次数,速率改变沿着正弦曲线;
DecelerateInterpolator:在动画开始的地方速率改变比较慢,然后开始减速;
LinearInterpolator:在动画的以均匀的速率改变。
以上的内容在XML 文件中的<set>标签中设置,同时可以增加android:shareInterpolator 命令行决定是否所有效果遵循同个Interpolator。
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true">
对于单纯的Java 文件控制,AnimationSet(true) 代表共享Interpolater 。
Animation animation = new AnimationSet(true);
Frame-By-Frame Animations 的使用方法。
在res 下的某个drawable 文件夹下放入要循环播放的图片资源,创建一个xml 文件,加入<animation-list>标签和<item> 子标签,加入图片资源命令行。在Java 文件中对imagView 调用setBackgroundResouce 方法即可。