Android中的AnimationSet使用

AnimatorSet:这个类为一组特定的动画指定次序。
总要办法如下:

play:该办法创建一个机关器对象用于创建束缚。

playTogether:设置同时运行一组动画

   pase:暂停一个正在运行的动画

   resume:从头运行暂停后的动画

   isRunning:断定动画是否正在运行

   isStarted:断定动画是否已经运行了


话不多说,直接上图:


这个场景其实就是一个用户的头像选择,最中间的为用户默认的头像,点击四周头像可以与中间的头像进行交换。交换的过程就是用到了Android动画中AnimationSet这个类。

onClick事件具体执行内容:

private void switchImage(ImageView image){
		if(!animSet.isStarted() && image.getId()!=img_center.getId()){  //判断动画是否在运行,并且点击图片若在中间则不交换
		ObjectAnimator anim1, anim2, anim3, anim4, 
		anim5, anim6, anim7, anim8, anim21, anim61;
		animSet = new AnimatorSet();
		anim1 = ObjectAnimator.ofFloat(image, "alpha",
				0.2f, 1f);
		anim2 = ObjectAnimator.ofFloat(image,
				"y",  image.getY() ,  img_center.getY());
		anim21 = ObjectAnimator.ofFloat(image,
				"x",  image.getX() ,  img_center.getX());
		anim3 = ObjectAnimator.ofFloat(image, "scaleX",
				1.0f, 1.2f);
		anim4 = ObjectAnimator.ofFloat(image, "scaleY",
				1.0f, 1.2f);
		
		anim5 = ObjectAnimator.ofFloat(img_center, "alpha",
				1f, 0.2f);
		anim6 = ObjectAnimator.ofFloat(img_center,
				"y",  img_center.getY() ,  image.getY());
		anim61 = ObjectAnimator.ofFloat(img_center,
				"x",  img_center.getX() ,  image.getX());
		anim7 = ObjectAnimator.ofFloat(img_center, "scaleX",
				1f, 0.8f);
		anim8 = ObjectAnimator.ofFloat(img_center, "scaleY",
				1f, 0.8f);
		animSet.play(anim1).with(anim2).with(anim3).with(anim4)
		.with(anim5).with(anim6).with(anim7).with(anim8).with(anim21).with(anim61);
		animSet.setDuration(1000);
		animSet.start();
		imgs.put(img_center, imgs.get(image));
		imgs.put(image, 22);
		image.setPadding(15,15,15,15);
		img_center.setPadding(0,0,0,0);
		img_center = image;		
		System.out.println("center_id:"+img_center.getId());
		}
	}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值