Question

What i want is that each animation, from the code below, to start with a delay, like a sequence. So i have this code:

   public void setAnimation(){
        View view;
        String animation = prefs.getString("animations", "Scale");
        String interpolator = prefs.getString("interpolators", "Bounce");
        Animation animate = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale_in);
        for(int i=0; i<gridView.getChildCount(); i++){
            view = gridView.getChildAt(i);

            view.startAnimation(animate);
        }
    }

because there is a for loop, all child animations will start instantly. I already tried with:

Thread.sleep....
Handler...
animate.setStartTime...
animate.setStartOffset...

but all child animations starts instantly.

I tried this method inside of loop, and the animations won't start:

animate.setAnimationListener(new AnimationListener(){
    public void onAnimationEnd(Animation arg0) {
        view.startAnimation(animate);
    }

    public void onAnimationRepeat(Animation arg0) {
    }

    public void onAnimationStart(Animation arg0) {
    }

});

Thanx in advance.

Was it helpful?

Solution

The solution is to create a GridLayoutAnimationController or LayoutAnimationController.

OTHER TIPS

I used LayoutAnimationController to show elements in LinearLayout with animation effect one by one using following code.

     Animation fadeIn = AnimationUtils.loadAnimation(context, R.anim.anim_fade_in);
//lnrContactContainer is LinearLayout.
            AnimationSet set = new AnimationSet(true);
            set.addAnimation(fadeIn);
            set.setDuration(500);
            controller = new LayoutAnimationController(set, 1f);
            lnrContactContainer.setLayoutAnimation(controller);          
            lnrContactContainer.setVisibility(View.VISIBLE);

But same approach does not work when I use it to show fadeout animation while hiding LinearLayout lnrContactContainer.setVisibility(View.GONE);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top