Por lo tanto, resulta que esto es mucho más directo de lo que imaginaba.
Creé un RelativeLayout a pantalla completa que solo se muestra mientras la animación está sucediendo.
tengo la posición de partida de mi botón enterrado como esto (que es divertido ver a estos mecanismos de codificación estilo C en Java, que son bastante raro en estos días:
int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
lo tanto, ahora tengo mi partida punto.
Mi punto final es una coordenada absoluta en la pantalla, puede asignar que sin embargo deseo
Entonces hago una pequeña clase de ayuda animaciones que me permite superar todas las coordenadas, la devolución de llamada, y el duración de la animación
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;
}
}
y necesitamos un oyente para hacernos saber cuando la animación se realiza para desactivarla
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();
}
};
Y por último lo tiramos todos juntos y presiona Ir
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();
bien, me he dado cuenta que a mí mismo, si no se interviene con una respuesta, voy a publicar mañana, para que otros puedan referencia. –
¿Tiene un tutorial para esto también? – ManishSB