Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Android] Gérer plusieurs animations

    17 mai 2012 à 21:47:37

    Bonjour,

    Voilà, actuellement je fais s'exécuter plusieurs animations à la fois et cela les empêche d'être fluide, elles sont saccadées :euh: . Quand j'exécute une seul animation à la fois l'animation est fluide tout est parfait.
    Comme toute mon application repose sur les animations j'aimerai bien savoir si il y a un moyen de les rendre fluide sans pour autant devoir les exécuter une par une :p .
    Merci par avance ! :)
    • Partager sur Facebook
    • Partager sur Twitter
      27 mai 2012 à 10:47:05

      Personne ne saurait me répondre ? :(
      • Partager sur Facebook
      • Partager sur Twitter
        27 mai 2012 à 10:56:05

        Bonjour,

        Normalement, il devrait être tout à fait possible d'exécuter plusieurs animations à la fois sans que cela soit saccadé.
        Sur quel terminal/émulateur fais-tu tes tests et pourrais-tu nous donner ton code pour qu'on puisse t'aider ?
        • Partager sur Facebook
        • Partager sur Twitter
        Si vous voulez me retrouver, rendez-vous sur ZesteDeSavoir.
          28 mai 2012 à 11:21:35

          Bonjour,

          Avant tout, merci de votre réponse ! :)

          Alors au sujet du terminal j'utilise mon propose Samsung Galaxy S qui tourne sous Android 2.3.3 . (J'ose même pas essayer sur un émulateur virtuel tellement ils ont des lags sur mon pc pourtant sans aucuns problèmes de lags)
          Je pense que ça vient donc pas de là.

          Ensuite pour ce qui est du code, tu trouveras que c'est peut être pas la meilleure méthode mais c'est la méthode la plus adaptée (à laquelle j'ai pensé) pour faire ce que je souhaite.

          Le voici :
          DisplayMetrics metrics = new DisplayMetrics(); 
                  getWindowManager().getDefaultDisplay().getMetrics(metrics); 
                  
                  largeur = metrics.widthPixels;
                  hauteur = metrics.heightPixels;
          
                  Absolute = (AbsoluteLayout)findViewById(R.id.Absolute);
          
                      Anim12 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim12.setDuration(12*hauteur);
          	    Anim13 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim13.setDuration(12*hauteur);
          	    Anim14 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim14.setDuration(12*hauteur);
          	    Anim15 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim15.setDuration(12*hauteur);
          	    Anim16 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim16.setDuration(12*hauteur);
          	    Anim17 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim17.setDuration(12*hauteur);
          	    Anim18 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim18.setDuration(12*hauteur);
          	    Anim19 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, (float) -(1.50*hauteur));
          	    Anim19.setDuration(12*hauteur);
          
                  int taille = (int)(Math.random() * 7 + 15);
              	int posx = (int)(Math.random() * ((102-taille)+2) + 2);
              	 
          		t1 = new TextView(this);
          		t1.setBackgroundDrawable(getResources().getDrawable(R.drawable.bulle));
          		t1.setLayoutParams(new AbsoluteLayout.LayoutParams((int) ((taille*largeur)/100), (int) ((taille*largeur)/100), (int) ((posx*largeur)/100), (int) (((taille+100)*hauteur)/100)));
          		Absolute.addView(t1);
                  // Ainsi de suite pour 8 TextView
          
                  Timer = new Timer();
                  Timer.scheduleAtFixedRate(new Animation(), 0, 250);
          


          J'ai simplifié le code de manière à ce que l'on voit uniquement ce qu'il peut nous intéresser.

          Et voici la partie qui lance les animations :

          class Animation extends TimerTask
          	{		
          		public void run()
                  {
                      FirstActivity.this.runOnUiThread(new Runnable()
                      {
                          public void run()
                          {
                          		if ((Affichage > 0)&(Affichage <= 8))
                          		{Affichage ++;}
                          		else if (Affichage == 9)
                          		{t3.startAnimation(Anim13);Affichage ++;}
                          		else if ((Affichage > 9)&(Affichage <= 12))
                          		{Affichage ++;}
                          		else if (Affichage == 13)
                          		{t4.startAnimation(Anim14);Affichage ++;}
                          		else if ((Affichage > 13)&(Affichage <= 17))
                          		{Affichage ++;}
                          		else if (Affichage == 18)
                          		{t5.startAnimation(Anim15);Affichage ++;}
                          		else if ((Affichage > 18)&(Affichage <= 21))
                          		{Affichage ++;}
                          		else if (Affichage == 22)
                          		{t6.startAnimation(Anim16);Affichage ++;}
                          		else if ((Affichage > 22)&(Affichage <= 25))
                          		{Affichage ++;}
                          		else if (Affichage == 26)
                          		{t7.startAnimation(Anim17);Affichage ++;}
                          		else if ((Affichage > 26)&(Affichage <= 31))
                          		{Affichage ++;}
                          		else if (Affichage == 32)
                          		{t8.startAnimation(Anim18);Affichage ++;}
                          		else if ((Affichage > 32)&(Affichage <= 34))
                          		{Affichage ++;}
                          		else if (Affichage == 35)
                          		{t9.startAnimation(Anim19);}
                          }
          
          				
                      });
                  }
          	}
          


          Le fait d'attendre que l'integer "Affichage" ai atteint un certain nombre me permet de lancer mes animations à une certaine intervalle les unes des autres (ce qui n'empêche qu'elles sont plusieurs à s'exécuter en même temps).

          Voilà en espérant que vous puissiez m'aider.
          • Partager sur Facebook
          • Partager sur Twitter
            7 juin 2012 à 18:50:37

            Je me permets de remonter le sujet car je ne sais toujours pas comment faire ? :(
            • Partager sur Facebook
            • Partager sur Twitter
              8 juin 2012 à 21:40:33

              Je n'ai utilisé que très peu les animations sous Android mais j'ai trouvé ce tutoriel qui pourrait sans doute t'aider.
              Le code de l'utilisation de ces multiples animations est très différent du code que tu nous exposes.
              • Partager sur Facebook
              • Partager sur Twitter
              Si vous voulez me retrouver, rendez-vous sur ZesteDeSavoir.
                10 juin 2012 à 11:47:46

                Merci de ta réponse, je vais voir ce que ça donne et j'espère que cela m'aidera ! :)
                • Partager sur Facebook
                • Partager sur Twitter

                [Android] Gérer plusieurs animations

                × 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.
                • Editeur
                • Markdown