Search code examples
javaandroidkotlinandroid-motionlayout

Motion Layout's KeyAttribute triggers immediately despite framepostion


My transition:

<Transition
    app:constraintSetEnd="@+id/end"
    app:constraintSetStart="@+id/start"
    app:motionInterpolator="linear">

    <KeyFrameSet>
        <KeyAttribute
            app:framePosition="80"
            app:motionTarget="@id/toolbar">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="8" />
        </KeyAttribute>
        <KeyAttribute
            app:framePosition="80"
            app:motionTarget="@id/navHostFragment">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="8" />
        </KeyAttribute>
        <KeyAttribute
            app:framePosition="80"
            app:motionTarget="@id/playerStatus">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="8" />
        </KeyAttribute>
    </KeyFrameSet>

    <OnSwipe
        app:dragDirection="dragUp"
        app:touchRegionId="@id/mlView" />

</Transition>

No matter what number I use in frameposition, keyattribute's visibility applies immediately in the start of the animation. Why?


Solution

  • Add <KeyAttribute>s for framePosition="0" to the layout's default value. Since there is no info on what your base values are, perhaps like so:

    <KeyFrameSet>
        <KeyAttribute
            app:framePosition="0"
            app:motionTarget="@id/toolbar">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="0" />
        </KeyAttribute>
        <KeyAttribute
            app:framePosition="0"
            app:motionTarget="@id/navHostFragment">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="0" />
        </KeyAttribute>
        <KeyAttribute
            app:framePosition="0"
            app:motionTarget="@id/playerStatus">
            <CustomAttribute
                app:attributeName="visibility"
                app:customIntegerValue="0" />
        </KeyAttribute>
    </KeyFrameSet>
    

    This will keep the target Views visible until the 79th Frame after which in the 80th frame of the transition they will disappear.