所以,事实证明,这比我想象的要简单得多。
我创建了一个全屏幕RelativeLayout,我只在动画发生时显示。
我得到我喜欢这个埋按钮的起始位置(这很有趣,看看在Java中使用这些C风格的编码机制,他们是非常罕见的,这些天:
int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
所以,现在我有我的起点点。
我的终点是一个绝对坐标在屏幕上,你可以分配自己的喜好
然后我做一点动画助手类,它让我通过在所有的坐标,回调,和动画的持续时间
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 to delete the ImageView and hide the animation Layout until we need it again.
clearAnimation();
}
};
最后一点,我们把它放在一起,然后按GO
int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
RelativeLayout rl = ((RelativeLayout)findViewById(R.id.sticker_animation_layout));
ImageView sticker = new ImageView(this);
int stickerId = getStickerIdFromButton(v);
if(stickerId == 0){
stickerAnimationPlaying = false;
return;
}
float destX = 200.0f;//arbitrary place on screen
float destY = 200.0f;//arbitrary place on screen
sticker.setBackgroundResource(stickerId);
sticker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rl.addView(sticker);
Animations anim = new Animations();
Animation a = anim.fromAtoB(startX, startY, destX, destY, animL,750);
sticker.setAnimation(a);
a.startNow();
好吧,我理解了它自己,如果没有人有答案风铃,我会后,明天,为他人参考。 – 2012-03-09 06:39:13
你也有这个教程吗? – ManishSB 2014-08-07 19:44:52