Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 688
Daniele Vitali Avatar asked Sep 20 '25 00:09

Daniele Vitali


1 Answers

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);
like image 137
Jordy vd Heijden Avatar answered Sep 21 '25 14:09

Jordy vd Heijden