2016-07-23 7 views
0

ich möchte einfache animation mit multi-images auf android studio ich habe 3 bilder (img1, img2, img3) und ich will img1 sichtbar zuerst dann nach einer halben sekunde img1 unsichtbar und img2 sichtbar, dann nach einer halben sekunde img2 unsichtbar und img3 sichtbar, dann nach einer halben Sekunde img3 unsichtbar und img1 sichtbar, also zurück zum ersten Bild wie Kreis 1> 2> 3> 1> 2> 3> 1> 2> 3 bis unbegrenzte Zeit, so wie kann ich das tun , bitteWie mache ich mein Bild sichtbar durch Zeitzähler?

Antwort

0
class ImageAnimation { 

    Activity activity; 
    android.os.Handler handler; 
    ImageView[] images = new ImageView[3];//three images array 
    int current = 0;//current image iterator 


    public ImageAnimation(Activity activity) { 

      handler = new android.os.Handler(); 


      images[0] = (ImageView) activity.findViewById(R.id.you_image1_id); 
      images[1] = (ImageView) activity.findViewById(R.id.you_image2_id); 
      images[2] = (ImageView) activity.findViewById(R.id.you_image3_id); 

      current = 0; 


    } 

    public void animateImages() { 


      handler.postDelayed(new Runnable() { 
        @Override 
        public void run() { 



        //loop for all images and animate it 
        for (int i = 0; i < images.length; i++) { 

          if (i!=current) 
            images[i].animate().alpha(1);//show 
          else 
            images[i].animate().alpha(0);//hide 
        } 

         if (current<images.length) 
          current++; 
         else 
          current=0;//again first one 


         //recurring using the same method - infinite loop 
         animateImages(); 

        } 
      }, 500); //half a second 

    } 
};