2013-11-28 9 views
6

Próbuję animować 3 obrazy jeden po drugim za pomocą animatora wartości, ale nie jestem w stanie zdecydować, jak wywołać trzy procedury obsługi po regularnych interwałach .. Załóżmy, że są 3 obrazy i robię trzy programy obsługi do animowania them.But jestem w stanie przynieść trzy obrazy w czasie, ale nie jedna po drugiej w regularnych intervals.Please PomocWartość Animator android

to mój UpdateListener który Wołam z mojego obsługi

public void startAnimation_image(final ImageView aniView) { 

    animator = ValueAnimator.ofFloat(0, .8f); 
    animator.setDuration(Constants.ANIM_DURATION); 

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

     int Low = 10; 
     int High = width-150; 
     int R = (int) ((Math.random() * (High - Low)) + Low); 

     @Override 
     public void onAnimationUpdate(ValueAnimator animation) { 
      float value = ((Float) (animation.getAnimatedValue())).floatValue(); 
      aniView.setTranslationX(R); 

      Log.e("mscale",150*mScale +""); 
      Log.e("value is", value+""); 

      aniView.setTranslationY((mDisplaySize.bottom + (150*mScale))*value); 

      x_point = aniView.getTranslationX(); 
      y_point = aniView.getTranslationY(); 
     } 
    }); 

    animator.addListener(new AnimatorListener() { 

     @Override 
     public void onAnimationStart(Animator arg0) { 

     } 
     @Override 
     public void onAnimationRepeat(Animator arg0) { 

     } 
     @Override 
     public void onAnimationEnd(Animator arg0) { 

      startAnimation(); 
     } 
     @Override 
     public void onAnimationCancel(Animator arg0) { 

     } 
    }); 

    animator.start(); 
} 

jest jeden z moich przewodników

@Override 
    public void handleMessage(Message msg) { 
     super.handleMessage(msg); 

     //int viewId = new Random().nextInt(STARS.length); 

     id = getApplicationContext().getResources().getIdentifier(STARS[0], "drawable", 
      getApplicationContext().getPackageName()); 

     inflate = LayoutInflater.from(StarsActivity2.this); 


     img[0].setVisibility(ImageView.VISIBLE); 
     img[0].setImageResource(id); 

     mAllImageViews.add(img[0]);   

     LayoutParams animationLayout = (LayoutParams) img[0].getLayoutParams(); 
     img[0].setLayoutParams(animationLayout); 
     Log.e("mHandler",img[0]+ ""); 
     startAnimation_image(img[0]);   
    } 
}; 

Istnieje similaarly trzy koparki i trzy detektory aktualizacji .. Proszę o pomoc ...

Odpowiedz

2

Można opóźnić animację przez offset ms wywołując

animation.setStartOffset(offset); 

więc dla trzech obrazów z czasem trwania ANIM_DURATION, ty może użyć następujących wartości, aby rozpocząć je sekwencyjnie (prawdopodobnie przekazując je jako parametr do startAnimation_image())

// note: this is for illustrative purposes. You should put this in a loop 
int firstOffset = 0 * ANIM_DURATION; // starts immediately 
int secondOffset = 1 * ANIM_DURATION; // starts after the first animation is finished 
int thirdOffset = 2 * ANIM_DURATION; // starts after the second animation is finished 
// ... and so on. 
+0

Dziękuję bardzo kochanie – XylemRaj

Powiązane problemy