2016-07-23 7 views
0

私はアンドロイドスタジオで複数の画像を使って簡単なアニメーションを作りたい 私は3つの画像(img1、img2、img3)を持っています そして最初にimg1を見せてから半分の後にimg1を見えなくしてからimg2を見せてから半分の後にimg2 invisible img3が表示されてから半分の時間が経過してimg3が表示されてからimg1が表示されるので、円のような最初の画像に戻って無限の時間に、 1> 2> 3> 1> 2> 3です。 、お願い:タイムカウンタで自分の画像を見えるようにするには?

答えて

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 

    } 
}; 
関連する問題