首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2013-12-02 
多米音乐点击收藏的动画(带图)??前段时间在EOE上看到关于这种动画的例子,不过那个例子做是的加入到购物车?

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

?

?

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

?

说一下主要的思路

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

? ? ? ? View.getLocationInWindow(int[] location)?

? ? ?

holder.favor.setOnClickListener(new OnClickListener() {@Overridepublic 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() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {// 去除动画层root.removeView(ll);}});

?比较简单.

热点排行