多米音乐点击保藏的动画(带图)
多米音乐点击收藏的动画(带图)
今天注意一下多米音乐,发现它已经改版了,不是这种动画,不过没所谓了.
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); } });
比较简单.