ZMY_补间动画

package com.bwei.day_06_tween_;

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.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView) findViewById(R.id.imageView);

    }

    /**
     * 透明
     *
     * @param v
     */
    public void alpha(View v) {
        // 得到AlphaAnimation对象,参数一:开始的透明度,参数二:结束的透明度
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
        // 持续时间
        alphaAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        alphaAnimation.setFillAfter(true);
        // 动画重复次数
        alphaAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        alphaAnimation.setRepeatMode(AlphaAnimation.RESTART);
        imageView.startAnimation(alphaAnimation);

    }

    /**
     * 放缩
     *
     * @param v
     */
    public void scale(View v) {
        /*
         * ScaleAnimation scaleAnimation=new ScaleAnimation(fromX, toX, fromY,
         * toY, pivotXType, pivotXValue, pivotYType, pivotYValue)
         */

        // 参数一:开始的x坐标,参数二:动画结束的x坐标,参数三:开始的y坐标,参数四:动画结束的y坐标,
        // 参数五:放缩时的中心点的x坐标位置的相对类型(有绝对,相对于父亲,相对于自己),参数六:中心点(放缩的中心点)x轴的位置,
        // 参数七:放缩时的中心点的Y坐标位置的相对类型(有绝对,相对于父亲,相对于自己),参数八:中心点(放缩的中心点)Y轴的位置,
        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1.0f, 0.0f, 1.0f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f);

        // 持续时间
        scaleAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        scaleAnimation.setFillAfter(true);
        // 动画重复次数
        scaleAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        scaleAnimation.setRepeatMode(Animation.RESTART);

        imageView.startAnimation(scaleAnimation);
    }

    /**
     * 位移
     *
     * @param v
     */
    public void translate(View v) {
        // TranslateAnimation translateAnimation=new
        // TranslateAnimation(fromXType, fromXValue, toXType, toXValue,
        // fromYType, fromYValue, toYType, toYValue)

        // 参数一:x轴起始点的相对类型,参数二:x轴的起始位置,参数三:x轴停止点的相对类型,参数四:x轴最终移动的距离(与起始点的相对距离)
        // //参数五:Y轴起始点的相对类型,参数六:Y轴的起始位置,参数七:Y轴停止点的相对类型,参数八:Y轴最终移动的距离(与起始点的相对距离)
        TranslateAnimation translateAnimation = new TranslateAnimation(

        Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1.0f,

        Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_SELF, 1.0f);

        // 持续时间
        translateAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        translateAnimation.setFillAfter(true);
        // 动画重复次数
        translateAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        translateAnimation.setRepeatMode(Animation.RESTART);

        imageView.startAnimation(translateAnimation);
    }

    /**
     * 旋转
     *
     * @param v
     */

    public void rotate(View v) {
        // RotateAnimation rotateAnimation=new RotateAnimation(fromDegrees,
        // toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)

        // 参数一:起始角度,参数二:旋转角度,
        // 参数三:圆心x轴坐标的相对位置类型,参数四:圆心x轴的位置,到起始点的距离
        // 参数五:圆心Y轴坐标的相对位置类型,参数六:圆心y轴的位置,到起始点的距离
        RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                1.0f);

        // 持续时间
        rotateAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        rotateAnimation.setFillAfter(true);
        // 动画重复次数
        rotateAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        rotateAnimation.setRepeatMode(Animation.RESTART);

        imageView.startAnimation(rotateAnimation);
    }

    /*
     * 动画合集
     */
    public void set(View v) {

        AnimationSet animationSet=new AnimationSet(false);
        
        
        //
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
        // 持续时间
        alphaAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        alphaAnimation.setFillAfter(true);
        // 动画重复次数
        alphaAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        alphaAnimation.setRepeatMode(AlphaAnimation.RESTART);
        //===============================================================================
        
        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1.0f, 0.0f, 1.0f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f);

        // 持续时间
        scaleAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        scaleAnimation.setFillAfter(true);
        // 动画重复次数
        scaleAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        scaleAnimation.setRepeatMode(Animation.RESTART);
    //======================================================================    
    
        
        RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                1.0f);

        // 持续时间
        rotateAnimation.setDuration(2000);
        // 动画结束时是否保持状态
        rotateAnimation.setFillAfter(true);
        // 动画重复次数
        rotateAnimation.setRepeatCount(2);
        // 设置动画重复的模式(从头开始)(从尾开始)
        rotateAnimation.setRepeatMode(Animation.RESTART);

/        
        
        //往动画集合里添加动画
        animationSet.addAnimation(alphaAnimation);
        
        animationSet.addAnimation(scaleAnimation);
        
        animationSet.addAnimation(rotateAnimation);
        
        animationSet.setDuration(5000);
        
        animationSet.setRepeatCount(3);
        
        imageView.startAnimation(animationSet);
        
        
    }

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值