簡體   English   中英

動畫圖像圖標從觸摸位置到右上角?

[英]Animate image icon from touch place to right-top corner?

我正在開發Android onlineShopping應用程序。我必須應用一些動畫。

  1. 購物車圖像顯示在屏幕的右上角。
  2. 屏幕上的每個項目都有“添加到購物車”按鈕。
  3. 當用戶按下此按鈕時,我必須播放動畫。
  4. 我有一個修復圖像應該從觸摸位置動畫到放置在屏幕右上角的購物車圖像。

請幫幫我。

提前致謝。

更新:

我嘗試將圖像從一個地方移動到另一個地方。

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

                img.startAnimation(anim);

這個圖像我想從觸摸位置動畫到右上角。 在此輸入圖像描述

最終,您希望使用動畫將視圖從一個位置移動到另一個位置。

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

//現在開始動畫,如下所述:

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

我希望它會有所幫助!!

我認為你正在尋找,你可以查看鏈接

鏈接在這里

在此輸入圖像描述

檢查這個例子希望這對你有幫助: http//developer.android.com/training/animation/zoom.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM