[英]Animate image icon from touch place to right-top corner?
我正在開發Android onlineShopping應用程序。我必須應用一些動畫。
請幫幫我。
提前致謝。
更新:
我嘗試將圖像從一個地方移動到另一個地方。
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.