alisonthemonster
alisonthemonster

Reputation: 1152

How to set transition duration programmatically in MotionLayout?

I set a new transition manually in code like this:

intro_motion_layout.setTransition(R.id.middle, R.id.end)

Is there a way I can also set the duration this way?

I have multiple ConstraintSets defined in XML and I switch between them when the first transition is complete using onTransitionCompleted. I have one Transition in my XML and it uses duration correctly there but the following Transitions that I set in code happen very quickly and I cant find a way to change their durations.

Upvotes: 5

Views: 6839

Answers (2)

odiggity
odiggity

Reputation: 1566

intro_motion_layout.setTransition(R.id.middle, R.id.end)
intro_motion_layout.setTransitionDuration(1000)
intro_motion_layout.transitionToEnd()

worked for me

Upvotes: 7

SwaiX
SwaiX

Reputation: 79

if you define your Transition on your xml, then you set your start/end id, it will take the information from xml

<Transition
    app:constraintSetStart="@id/bottom_sheet_closed"
    app:constraintSetEnd="@id/bottom_sheet_open"
    app:duration="1550"
    app:interpolator="easeIn">

    <OnSwipe
        app:dragDirection="dragUp"
        app:moveWhenScrollAtTop="true"
        app:touchAnchorId="@id/divider"
        app:touchAnchorSide="top" />

</Transition>

then programmatically you can do:

root.motion_layout.setTransition(R.id.bottom_sheet_closed, R.id.bottom_sheet_open)
root.motion_layout.transitionToEnd()

and everythink will work

Upvotes: -1

Related Questions