Android开发之Animations(三)

来源:互联网 发布:旅游景点地图软件 编辑:程序博客网 时间:2024/05/17 23:39

什么是AnimationSet?

1.AnimationSet是Animation的子类;

2.一个AnimationSet包含了一系列的Animation;

3.设置AnimationSet对象的属性,相当于设置的AnimationSet对象包含的所有Animation对象属性

4.使用AnimationSet可以整合多种动画效果


AnimationSet的使用方法

1.在MainActivity.java中创建一个AnimationSet对象,然后再创建多个动画对象

2.将多个动画对象添加到AnimationSet对象中

3.设置AnimationSet对象的属性

4.将ImageView对象与AnimationSet对象进行绑定


MainActivity.java:

package com.mycompany.animations3;import android.support.v7.app.AppCompatActivity;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.AnimationUtils;import android.view.animation.RotateAnimation;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends AppCompatActivity {    private ImageView imageView;    private Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        imageView = (ImageView) findViewById(R.id.imageView);        button = (Button) findViewById(R.id.button);        button.setOnClickListener(new ButtonListener());    }    class ButtonListener implements View.OnClickListener{        @Override        public void onClick(View v) {            //  创建AnimationSet对象            AnimationSet animationSet = new AnimationSet(true);            //  创建多个动画对象            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);            RotateAnimation rotateAnimation = new RotateAnimation(0, 360,                    Animation.RELATIVE_TO_SELF, 0.5f,                    Animation.RELATIVE_TO_SELF, 0.5f);            //  将多个动画对象添加到AnimationSet对象中            animationSet.addAnimation(alphaAnimation);            animationSet.addAnimation(rotateAnimation);            //  设置AnimationSet对象的属性            animationSet.setDuration(3000);            animationSet.setStartOffset(2000);            //  将ImageView对象与AnimationSet对象进行绑定            imageView.startAnimation(animationSet);        }    }}



什么是Interpolator?

Interpolator定义了动画变化的速率,在Animations框架当中定义了以下几种Interpolator:

AccelerateDecelerateInterpolator:在动画开始与结束的地方速率改变比较慢,在中间的时候开始加速

AccelerateInterpolator:在动画开始的地方速率改变比较慢,然后开始加速

CycleInterpolator:动画循环播放特定的次数,速率沿着正弦曲线改变

DecelerateInterpolator:在动画开始的地方速率改变比较慢,然后开始减速

LinearInterpolator:以均匀速率改变


Interpolator的使用方法

Interpolator属性可以在Animation resource file中设置,也可以在代码中进行设置


0 0
原创粉丝点击