王学岗属性动画上(七)----------AnimatorSet动画集合

AnimatorSet动画集合


package com.example.seven;

import android.animation.AnimatorSet; 
import android.animation.ObjectAnimator; 
import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ImageView; 
@SuppressLint(“NewApi”) 
public class MainActivity extends Activity {

private ImageView iv_zhangxin;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    iv_zhangxin = (ImageView) findViewById(R.id.iv_zhangxin);
    MyClick mc = new MyClick();
    iv_zhangxin.setOnClickListener(mc);
}

private class MyClick implements OnClickListener {

    @Override
    public void onClick(View v) {
     ObjectAnimator scaleXAnimator=ObjectAnimator.ofFloat(iv_zhangxin, "scaleX", 1.0f,2.0f);
     ObjectAnimator scaleYAnimator=ObjectAnimator.ofFloat(iv_zhangxin, "scaleY", 1.0f,2.0f);
     AnimatorSet animatorSet=new AnimatorSet();
     animatorSet.setDuration(5000);
     //可以放可变参数,集合(集合里面放动画),List<ObjectAnimator>等等
     animatorSet.playTogether(scaleXAnimator,scaleYAnimator);
     animatorSet.start();
    }

}
}

AnimatorSet是一个动画集合。
再看一个例子

  ObjectAnimator animator1 = ObjectAnimator.ofFloat(iv, "translationX", 0f, 500F);

        ObjectAnimator animator2 = ObjectAnimator.ofFloat(iv, "alpha", 0f, 1f);

        ObjectAnimator animator3 = ObjectAnimator.ofFloat(iv, "scaleX", 0f, 2f);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(500);

   
        //animatorSet.playTogether(animator1,animator2,animator3);//一起执行
        animatorSet.playSequentially(animator2, animator1, animator3);//顺序执行,按照添加的顺序一起执行。不能添加相同的动画
        animatorSet.start();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值