Au début de mon application, lorsqu'elle se lance, je voudrai qu'un objet soit animé d'une translation, puis qu'il garde sa position à la fin de la translation, et ensuite il faut que je sois "capable" de cliquer dessus...
Mon problème est que l'objet ne reste pas à la position de la fin de la translation...
Pour que l'objet reste à la position de la fin de l'animation j'utilise : setFillAfter(true). Peut être que je ne le met pas au bon endroit ou que je l'utilise mal... Je ne sais pas...
Voici le code :
package teste.animation;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
public class MainActivity extends Activity
{
private Button boutton = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boutton = new Button(this);
boutton = (Button)findViewById(R.id.button1);
boutton.setOnTouchListener(bautton);
AnimationSet a = new AnimationSet(true); //Création de l'animation
//a.setFillAfter(true);
Animation translation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 200, Animation.RELATIVE_TO_SELF, 500);
translation.setDuration(1000);
translation.setFillAfter(true);
a.addAnimation(translation);
boutton.startAnimation(a);
translation.setAnimationListener(new AnimationListener()
{
public void onAnimationStart(Animation animation)
{
}
public void onAnimationEnd(Animation arg0)
{
arg0.cancel();
}
public void onAnimationRepeat(Animation animation)
{
}
});
}
private OnTouchListener bautton = new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent e)
{
switch(e.getAction())
{
case MotionEvent.ACTION_DOWN:
boutton.setX(e.getX() + v.getX());
boutton.setY(e.getY() + v.getY());
break;
case MotionEvent.ACTION_MOVE:
boutton.setX(e.getX() + v.getX());
boutton.setY(e.getY() + v.getY());
break;
case MotionEvent.ACTION_UP:
boutton.setX(e.getX() + v.getX());
boutton.setY(e.getY() + v.getY());
break;
}
return true;
}
};
}
Avez-vous une idée ? Pourquoi setFillAfter(true) ne fonctionne pas (en gros) ?
[Android] Animation + clic
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.