从动画触摸的地方右上角的图像图标? [英] Animate image icon from touch place to right-top corner?

查看:182
本文介绍了从动画触摸的地方右上角的图像图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android onlineShopping application.I工作必须申请一些动画。

I am working on Android onlineShopping application.I have to apply some animation.


  1. 车图像在屏幕的右上角的显示。

  2. 项目清单上屏幕添加到购物车按钮,每个项目。

  3. 当用户preSS这个按钮我必须发挥动画。

  4. 我应该从触摸位置动画一个Fix影像
    购物车图像放置在屏幕的右上角的。

请帮助我。

先谢谢了。

更新:

我试过这个图像从一个地方移动到另一个地方。

I Tried this to move image from one place to another.

TranslateAnimation anim = new TranslateAnimation(0,0,200,200);              
                anim.setDuration(3000);

                img.startAnimation(anim);

这个形象我想从触摸位置到右上角的动画。

This image I want to animate from touch position to right-top corner.

推荐答案

最终你想从一个位置移动以便与动画的其他位置。

ultimately you want to move a view from one position to another position with animation.

第1步:
得到这种观点的初始位置

int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);     
float startX = fromLoc[0];
float startY = fromLoc[1];

第2步:
获得目标位置

int toLoc[] = new int[2];
desti.getLocationOnScreen(toLoc);       
float destX = toLoc[0];
float destY = toLoc[1];

第3步:
创建一个类来管理动画

        public class Animations {
public Animation fromAtoB(float fromX, float fromY, float toX, float toY, AnimationListener l, int speed){


        Animation fromAtoB = new TranslateAnimation(
                Animation.ABSOLUTE, //from xType
                fromX, 
                Animation.ABSOLUTE, //to xType
                toX, 
                Animation.ABSOLUTE, //from yType 
                fromY, 
                Animation.ABSOLUTE, //to yType 
                toY
                 );

        fromAtoB.setDuration(speed);
        fromAtoB.setInterpolator(new AnticipateOvershootInterpolator(1.0f));


        if(l != null)
            fromAtoB.setAnimationListener(l);               
                return fromAtoB;
    }
}

第4步:
添加animationlistener并在需要的视图启动动画

     AnimationListener animL = new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {     
        }

        @Override
        public void onAnimationRepeat(Animation animation) {        
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            //this is just a method call you can create to delete the animated view or hide it until you need it again.
            clearAnimation();       
        }
    };

//下面现在提到启动动画:

//now start animation as mentioned below:

Animations anim = new Animations();
    Animation a = anim.fromAtoB(startX, startY, destX, destY, animL,850);
    v.setAnimation(a);
    a.startNow();

我希望这会有所帮助!

I hope it will be helpful !!

这篇关于从动画触摸的地方右上角的图像图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆