【问题标题】:Animate image icon from touch place to right-top corner?从触摸位置到右上角的动画图像图标?
【发布时间】:2013-10-23 06:36:00
【问题描述】:

我正在开发 Android onlineShopping 应用程序。我必须应用一些动画。

  1. 购物车图像显示在屏幕右上角。
  2. 屏幕上的项目列表显示每个项目都带有“添加到购物车”按钮。
  3. 当用户按下此按钮时,我必须播放动画。
  4. 我有一个修复图像应该从触摸位置动画到 cart-image 位于屏幕的右上角。

请帮帮我。

提前致谢。

更新:

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

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

                img.startAnimation(anim);

我想将此图像从触摸位置动画化到右上角。

【问题讨论】:

  • @Indiandroid 我从来没有接触过动画。我只是看到一个演示,但没有满足要求。
  • 正如你所提到的,你想从列表视图项目到右上角做动画?如果可能,然后添加屏幕截图。
  • @Indiandroid 是的,兄弟,请帮帮我。无法从动画演示代码 sn-ps 中弄清楚。
  • @Indiandroid 是的,我会帮忙添加图片以便我弄清楚。

标签: android animation viewanimator


【解决方案1】:

最终你想通过动画将视图从一个位置移动到另一个位置。

第 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;
    }
}

第四步: 添加动画监听器并在所需视图上启动动画

     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();       
        }
    };

//现在开始动画如下:

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

希望对你有帮助!!

【讨论】:

  • 感谢您的回答听起来很有希望。将尝试使用此代码更新我的情况。
【解决方案2】:

我想你正是​​在找,你可以查看链接

link here

【讨论】:

    【解决方案3】:

    检查这个例子希望这对你有帮助: http://developer.android.com/training/animation/zoom.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      相关资源
      最近更新 更多