Daniele Vitali
Daniele Vitali

Reputation: 3858

Delay animation with Transitions framework

I am trying to delay a transition using TransitionManager.beginDelayedTransition() from the support library.

I want to use AutoTransition for make a LinearLayout appearing/disappearing. The animation works perfectly as expected, except that it is not delayed.

TransitionManager.beginDelayedTransition(rootViewGroup, new AutoTransition().setStartDelay(1000));
linearLayout.setVisibility(View.VISIBLE);

The linearLayout is in the hierarchy of the rootViewGroup of course.

Upvotes: 4

Views: 3017

Answers (1)

Jordy vd Heijden
Jordy vd Heijden

Reputation: 132

I did some testing, but unfortunately I am also not able to make it work. It looks like the setStartDelay only works on the ChangeBounds transition.

See the following example (when you set the startDelay on the first transition, the delay won't work):

linearLayout = (LinearLayout) findViewById(R.id.testLinearLayout);
mSceneRoot = (ViewGroup) findViewById(R.id.rootView);
mStaggeredTransition = new TransitionSet();

Transition first = new Fade(Fade.OUT);
Transition second = new ChangeBounds();
Transition third = new Fade(Fade.IN);
second.setStartDelay(1000).addTarget(linearLayout);

mStaggeredTransition.setOrdering(ORDERING_SEQUENTIAL);
mStaggeredTransition.addTransition(first).addTransition(second).addTransition(third);

findViewById(R.id.testbutton).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        linearLayout.setVisibility(View.GONE);
        TransitionManager.beginDelayedTransition(mSceneRoot, mStaggeredTransition);
        linearLayout.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout.getLayoutParams();
        params.addRule(ALIGN_PARENT_END);
        linearLayout.setLayoutParams(params);
    }
});

So I suggest you to use something like this:

mSceneRoot.postDelayed(new Runnable() {
        @Override
        public void run() {
            TransitionManager.beginDelayedTransition(rootViewGroup, new AutoTransition().setStartDelay(1000));
            linearLayout.setVisibility(View.VISIBLE);
        }
    }, 1000);

Upvotes: 5

Related Questions