Android: cómo reiniciar la animación después de borrarla

Can't find a solution to start the animation again after i call myImageView.clearAnimation(). The animation gets set in onPageSelected but the startoffset timeout dont work.

Or is there any other method to cancel thr animation to get a untouched imageview and when onPageSelected is called start the same animation for the same view agian.

I tryed to call myImageView.getAnimation().retart() in onPageScrollStateChanged but the animation is still on the view...

Aquí está mi código:

public class myActivity extends Activity {
...
private ImageView myImageView;

private static final Integer startOffset = 5000;
private static final Integer duration= 2500;

@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    currentImageView = (ImageView) findViewById(R.id.dashboardIndicator);
    currentImageView.setAnimation(indicatorAnimation());
    ...
}

private Animation indicatorAnimation() {
    Animation alphaAnimation = new AlphaAnimation(1, 0.2F);
    alphaAnimation.setInterpolator(new AccelerateInterpolator());
    alphaAnimation.setStartOffset(startOffset);
    alphaAnimation.setDuration(duration);
    alphaAnimation.setFillAfter(true);

    return alphaAnimation;
}

ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
        // Need here to start the animation again
        myImageView.setAnimation(indicatorAnimation());
        // Set's the animation but don't starts it after the startOffset timeout
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }

    @Override
    public void onPageScrollStateChanged(int position) {
        // Need here to cancel the animation to have no Alpha value on the imageview
        myImageView.clearAnimation();
        // image view 100% visible
    }
};}

preguntado el 03 de mayo de 12 a las 13:05

1 Respuestas

you do not need to clear the animation, call starAnimation directly

contestado el 03 de mayo de 12 a las 13:05

the animation should stop when scrolling from page to page, when finished scrolling then should the animation start after an timeout... - Andrés

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.