FDM.Pro
FDM.Pro

Reputation: 37

material design animate android

Hi I try to animate list of Views in layout to be scale_up but each of them must have wait for 100 millisecond after last view start it's animation. I try to set delay for them:

for (View view: views) {

            AnimatorSet animator = (AnimatorSet)AnimatorInflater.loadAnimator(context, R.animator.edit_text_open);
            animator.setStartDelay(counter++ * 100);
            Log.e("counter number:", "" + counter);
            animator.setTarget(view);
            animator.start();
        }

but it's not work all View animate together. and one more thing is there any good recurse about material design animations I try to make animation like shows in every where with material design I just don't know how they do it.

Upvotes: 0

Views: 182

Answers (2)

FDM.Pro
FDM.Pro

Reputation: 37

As @Stack Overflowerrr say in last answer there is the code:

t.scheduleAtFixedRate(new TimerTask() {
            // Do stuff
            @Override
            public void run() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        AnimatorSet animator = (AnimatorSet)AnimatorInflater.loadAnimator(MainActivity.this, R.animator.edit_text_open);
                        animator.setTarget(views.get(count));
                        animator.start();
                        Log.e("counter", "" + count);
                    }
                });

                count++;

                if (count + 1 >= views.size()) //assuming views as List<View>
                    t.cancel();
            }
        }, 0, 500);

and I declare these two as global:

int count = 0;
Timer t = new Timer();

again many thans Stack Overflowerrr.

Upvotes: 0

Stack Overflowerrr
Stack Overflowerrr

Reputation: 372

Initializing AnimatorSet

AnimatorSet animator = (AnimatorSet)AnimatorInflater.loadAnimator(context, R.animator.edit_text_open);

Using Timer will get the task done

Timer t = new Timer();
int count = 0;
t.scheduleAtFixedRate(new TimerTask() {
    // Do stuff
    animator.setTarget(views.get(count));
    animator.start();
    count++;
    if (count >= views.size()) //assuming views as List<View>
        t.cancel();
}, 0, 100);

Hope, that helps. Happy Coding!!!

Upvotes: 1

Related Questions