多米音乐点击收藏的动画(带图)

今天注意一下多米音乐,发现它已经改版了,不是这种动画,不过没所谓了.

t先看图,不多说:



 

 

前段时间在EOE上看到关于这种动画的例子,不过那个例子做是的加入到购物车

 

说一下主要的思路

 1、点击listview,得到当前点击Button的坐标(动画开始坐标)

        View.getLocationInWindow(int[] location) 

     

holder.favor.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (endLocation == null) {
						endLocation = new int[2];
						// 得到底部图片的坐标作为动画运动的结束坐标
						ivBottom.getLocationInWindow(endLocation);
					}
					// 得到当前图片的坐标作为动画运动的开始坐标
					v.getLocationInWindow(startLocation);
					ivFavor = new ImageView(mContext);
					ivFavor.setImageResource(R.drawable.icon_favor);
					startAnima(ivFavor);
				}
			});

 

2、建立一个动画层,把动画层加入到根视图,把运动的图片加入到动画翅,

 

 

//得到根视图,后面把动画层加到根视图
		root = (ViewGroup) getWindow().getDecorView();
// 新建一个linearLayout(动画层)
		final LinearLayout ll = new LinearLayout(this);
		LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.MATCH_PARENT);

		root.addView(ll);

 3、播放动画(可用AminationSet)

AnimationSet set1 = new AnimationSet(false);
		// X轴上的动画
		TranslateAnimation aX = new TranslateAnimation(0, endLocation[0]
				- startLocation[0], 0, 0);
		aX.setFillAfter(true);
		// 线性变化
		aX.setInterpolator(new LinearInterpolator());
		aX.setDuration(800);

		// Y轴上的动画(向下运动部分)
		TranslateAnimation aYdown = new TranslateAnimation(0, 0, 0,
				endLocation[1] - startLocation[1]);
		aYdown.setFillAfter(true);
		// 加速
		aYdown.setInterpolator(new AccelerateInterpolator());
		aYdown.setStartOffset(200);
		aYdown.setDuration(600);

		// Y轴上的动画(向上运动部分)
		TranslateAnimation aYup = new TranslateAnimation(0, 0, 0, -20);
		aYup.setFillAfter(true);
		aYup.setDuration(200);
		// 减速
		aYup.setInterpolator(new DecelerateInterpolator());

		set1.addAnimation(aX);
		set1.addAnimation(aYdown);
		set1.addAnimation(aYup);
		set1.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				// 去除动画层
				root.removeView(ll);
			}
		});

 比较简单.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值