Comment faire tourner un android icône sur son centre?
J'ai écrit ce qui suit à tour de ma icône sur le centre de l'écran et au lieu qu'il tourne autour du coin supérieur gauche (c'est à dire, de l'origine x=0, y=0 de l'ImageView). Il doit être simple à définir certains attributs de l'ImageView ou la RotateAnimation, mais je ne peux pas le comprendre.
public class IconPromoActivity extends Activity {
private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = -10.0f * 360.0f;//3.141592654f * 32.0f;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView favicon = (ImageView) findViewById(R.id.favicon);
RotateAnimation r; //= new RotateAnimation(ROTATE_FROM, ROTATE_TO);
r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, 0, 0, 40, 0);
r.setDuration((long) 2*1500);
r.setRepeatCount(0);
favicon.startAnimation(r);
}
}
Vous devez vous connecter pour publier un commentaire.
Essayer:
r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
Cela fonctionne pour moi:
rotationAnimation.setDuration(Animation.INFINITE);
et quand vous voulez arrêter l'animation:ImageView myRotatingImage = (ImageView) mRoot.findViewById(R.id.my_rotating_image);
myRotatingImage.clearAnimation();
Ici est l'exemple complet