Android AnimationSet使用

37 篇文章 0 订阅
package com.example.thinkpad.animation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
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 Main3Activity extends AppCompatActivity {
    ImageView imageView0;
    ImageView imageView1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        imageView0=(ImageView)findViewById(R.id.img0);
        imageView1=(ImageView)findViewById(R.id.img1);
        TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0f,
                Animation.RELATIVE_TO_PARENT,0.5f,
                Animation.RELATIVE_TO_PARENT,0f,
                Animation.RELATIVE_TO_PARENT,-0.5f);
        translateAnimation.setDuration(3000);
        translateAnimation.setRepeatCount(1);
        RotateAnimation rotateAnimation=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        rotateAnimation.setRepeatCount(Animation.INFINITE);
        rotateAnimation.setDuration(3000);
        ScaleAnimation scaleAnimation=new ScaleAnimation(1.0f,0.5f,1.0f,0.5f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        final AlphaAnimation alphaAnimation=new AlphaAnimation(1.0f,0.0f);
        final AnimationSet animationSet=new AnimationSet(false);
        scaleAnimation.setDuration(3000);
        scaleAnimation.setRepeatCount(1);
        alphaAnimation.setRepeatCount(1);
        alphaAnimation.setDuration(3000);
        animationSet.addAnimation(rotateAnimation);
        animationSet.addAnimation(translateAnimation);
       animationSet.addAnimation(alphaAnimation);
       animationSet.addAnimation(scaleAnimation);
        RotateAnimation rotateAnimation1=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        rotateAnimation1.setRepeatCount(2);
        rotateAnimation1.setDuration(3000);


        rotateAnimation1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
         Log.d("onstart","start");
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                imageView1.setAnimation(animationSet);
                imageView1.startAnimation(animationSet);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

                    Log.d("repeat3","goodgood");


            }
        });
        imageView0.setAnimation(rotateAnimation1);

    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值