これは、私が想像していたよりはるかに単純です。
私はアニメーションが起こっている間だけ表示する、フルスクリーンの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();
}
};
をクリアするために行われたときに知っているように、リスナーが必要そして最後に、私たちは一緒にすべてを投げるとプレスが
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();
[OK]を、私は誰もが答えでチャイムない場合は他の人が参照するために、私は、明日それを投稿します、自分自身をそれを考え出しました。 –
これについてのチュートリアルもありますか? – ManishSB