MotionLayout: multiple cumulative transitions2019 Community Moderator ElectionHow to create RecyclerView with multiple view type?How to handle return transition with shared elements?Problem with multiple Transitions in Android MotionLayoutHow to get barriers to work with MotionLayoutMotionLayout apply loadLayoutDescriptionHow to set transition duration programmatically in MotionLayout?MotionLayout not recognizingMotionLayout resets views when transition startsMotionLayout: how to animate marginMotionLayout - clicking on the layout behaves incorrectly

Is this Paypal Github SDK reference really a dangerous site?

After Brexit, will the EU recognize British passports that are valid for more than ten years?

Why is there an extra space when I type "ls" on the Desktop?

What is better: yes / no radio, or simple checkbox?

Rationale to prefer local variables over instance variables?

How to recover against Snake as a heavyweight character?

Is it a Cyclops number? "Nobody" knows!

How to make sure I'm assertive enough in contact with subordinates?

3.5% Interest Student Loan or use all of my savings on Tuition?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

Boss Telling direct supervisor I snitched

Are small insurances worth it?

How do you make a gun that shoots melee weapons and/or swords?

Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?

Short SF story. Females use stingers to implant eggs in yearfathers

Vector-transposing function

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

Mixed Feelings - What am I

Was this cameo in Captain Marvel computer generated?

Inorganic chemistry handbook with reaction lists

Sort array by month and year

What would be the most expensive material to an intergalactic society?

Why does a car's steering wheel get lighter with increasing speed

Short story about cities being connected by a conveyor belt



MotionLayout: multiple cumulative transitions



2019 Community Moderator ElectionHow to create RecyclerView with multiple view type?How to handle return transition with shared elements?Problem with multiple Transitions in Android MotionLayoutHow to get barriers to work with MotionLayoutMotionLayout apply loadLayoutDescriptionHow to set transition duration programmatically in MotionLayout?MotionLayout not recognizingMotionLayout resets views when transition startsMotionLayout: how to animate marginMotionLayout - clicking on the layout behaves incorrectly










0















I'm using MotionLayout and am trying to apply a series of transitions (defined in MotionScene file). For example Transition1 changes position of View1, and then Transition2 subsequently changes position of View2. The issue I'm seeing is that Transition2 is causing View1 to revert to it's original layout. I'm triggering the transitions using calls to transitionToState() (I've also tried explicitly providing start/end state for transition using setTransition() and then calling transitionToEnd()).



I saw comment in https://www.raywenderlich.com/8883-motionlayout-tutorial-for-android-getting-started that




if you don’t provide an end constraint for a view, it will
disappear. This happens because the library doesn’t know which
constraints it should apply at the end of the animation




Is it necessary to also include info on View1 layout in ConstraintSet for Transition2?



There is a "Multi State" example in https://github.com/googlesamples/android-ConstraintLayoutExamples/blob/master/README.md but it looks like transitions included all start from single base state (rather than being "cumulative")










share|improve this question




























    0















    I'm using MotionLayout and am trying to apply a series of transitions (defined in MotionScene file). For example Transition1 changes position of View1, and then Transition2 subsequently changes position of View2. The issue I'm seeing is that Transition2 is causing View1 to revert to it's original layout. I'm triggering the transitions using calls to transitionToState() (I've also tried explicitly providing start/end state for transition using setTransition() and then calling transitionToEnd()).



    I saw comment in https://www.raywenderlich.com/8883-motionlayout-tutorial-for-android-getting-started that




    if you don’t provide an end constraint for a view, it will
    disappear. This happens because the library doesn’t know which
    constraints it should apply at the end of the animation




    Is it necessary to also include info on View1 layout in ConstraintSet for Transition2?



    There is a "Multi State" example in https://github.com/googlesamples/android-ConstraintLayoutExamples/blob/master/README.md but it looks like transitions included all start from single base state (rather than being "cumulative")










    share|improve this question


























      0












      0








      0








      I'm using MotionLayout and am trying to apply a series of transitions (defined in MotionScene file). For example Transition1 changes position of View1, and then Transition2 subsequently changes position of View2. The issue I'm seeing is that Transition2 is causing View1 to revert to it's original layout. I'm triggering the transitions using calls to transitionToState() (I've also tried explicitly providing start/end state for transition using setTransition() and then calling transitionToEnd()).



      I saw comment in https://www.raywenderlich.com/8883-motionlayout-tutorial-for-android-getting-started that




      if you don’t provide an end constraint for a view, it will
      disappear. This happens because the library doesn’t know which
      constraints it should apply at the end of the animation




      Is it necessary to also include info on View1 layout in ConstraintSet for Transition2?



      There is a "Multi State" example in https://github.com/googlesamples/android-ConstraintLayoutExamples/blob/master/README.md but it looks like transitions included all start from single base state (rather than being "cumulative")










      share|improve this question
















      I'm using MotionLayout and am trying to apply a series of transitions (defined in MotionScene file). For example Transition1 changes position of View1, and then Transition2 subsequently changes position of View2. The issue I'm seeing is that Transition2 is causing View1 to revert to it's original layout. I'm triggering the transitions using calls to transitionToState() (I've also tried explicitly providing start/end state for transition using setTransition() and then calling transitionToEnd()).



      I saw comment in https://www.raywenderlich.com/8883-motionlayout-tutorial-for-android-getting-started that




      if you don’t provide an end constraint for a view, it will
      disappear. This happens because the library doesn’t know which
      constraints it should apply at the end of the animation




      Is it necessary to also include info on View1 layout in ConstraintSet for Transition2?



      There is a "Multi State" example in https://github.com/googlesamples/android-ConstraintLayoutExamples/blob/master/README.md but it looks like transitions included all start from single base state (rather than being "cumulative")







      android android-motionlayout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      John O'Reilly

















      asked 2 days ago









      John O'ReillyJohn O'Reilly

      5,69432031




      5,69432031






















          2 Answers
          2






          active

          oldest

          votes


















          1














          As @hoford said, the ConstraintSets are not merged each time they change. Apparently, this is also not possible without using reflection, although it would definitely be useful. Anyway, here is how to do it using reflection (through a few extension functions).



          I did create my own TransitionListener base class to provide support annotations and readable value names.
          The extension functions can be found here.



          What you can do is merge the two ConstraintSets and then mutate the endConstraintSet which can be obtained through TransitionListener#onTransitionChange:



          class AccumulativeTransitionListener: TransitionListener() 

          var didApplyConstraintSet = false

          override fun onTransitionChange(view: MotionLayout, @IdRes startConstraintSetId: Int, @IdRes endConstraintSetId: Int, progress: Float)
          if (!didApplyConstraintSet)
          // Let's retrieve our ConstraintSets first
          val startConstraintSet = view.getConstraintSet(startConstraintSetId)
          val endConstraintSet = view.getConstraintSet(endConstraintSetId)
          // Merge them (using an extension function)
          val mergedConstraintSet = startConstraintSet + endConstraintSet
          // Clear + Set them
          endConstraintSet.setConstraints(mergedConstraintSet)
          didApplyConstraintSet = true



          override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int)
          didApplyConstraintSet = false





          To not merge and apply the ConstraintSets each time TransitionListener#onTransitionChange is being called, there's a simple helper variable.



          Lastly, you have to attach the listener to your MotionLayout:



          val accumulativeListener = AccumulativeTransitionListener()
          motionLayout.setTransitionListener(accumulativeListener)


          Let me know if that works or if there are any bugs!






          share|improve this answer






























            1














            Transitions are not delta of state. They go from state to state.
            ConstraintSets define those states.



            ConstraintSets (within the context of a MotionScene) define a state which is the base layout + your changes described in the tag.






            share|improve this answer























            • OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

              – John O'Reilly
              2 days ago










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027526%2fmotionlayout-multiple-cumulative-transitions%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            As @hoford said, the ConstraintSets are not merged each time they change. Apparently, this is also not possible without using reflection, although it would definitely be useful. Anyway, here is how to do it using reflection (through a few extension functions).



            I did create my own TransitionListener base class to provide support annotations and readable value names.
            The extension functions can be found here.



            What you can do is merge the two ConstraintSets and then mutate the endConstraintSet which can be obtained through TransitionListener#onTransitionChange:



            class AccumulativeTransitionListener: TransitionListener() 

            var didApplyConstraintSet = false

            override fun onTransitionChange(view: MotionLayout, @IdRes startConstraintSetId: Int, @IdRes endConstraintSetId: Int, progress: Float)
            if (!didApplyConstraintSet)
            // Let's retrieve our ConstraintSets first
            val startConstraintSet = view.getConstraintSet(startConstraintSetId)
            val endConstraintSet = view.getConstraintSet(endConstraintSetId)
            // Merge them (using an extension function)
            val mergedConstraintSet = startConstraintSet + endConstraintSet
            // Clear + Set them
            endConstraintSet.setConstraints(mergedConstraintSet)
            didApplyConstraintSet = true



            override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int)
            didApplyConstraintSet = false





            To not merge and apply the ConstraintSets each time TransitionListener#onTransitionChange is being called, there's a simple helper variable.



            Lastly, you have to attach the listener to your MotionLayout:



            val accumulativeListener = AccumulativeTransitionListener()
            motionLayout.setTransitionListener(accumulativeListener)


            Let me know if that works or if there are any bugs!






            share|improve this answer



























              1














              As @hoford said, the ConstraintSets are not merged each time they change. Apparently, this is also not possible without using reflection, although it would definitely be useful. Anyway, here is how to do it using reflection (through a few extension functions).



              I did create my own TransitionListener base class to provide support annotations and readable value names.
              The extension functions can be found here.



              What you can do is merge the two ConstraintSets and then mutate the endConstraintSet which can be obtained through TransitionListener#onTransitionChange:



              class AccumulativeTransitionListener: TransitionListener() 

              var didApplyConstraintSet = false

              override fun onTransitionChange(view: MotionLayout, @IdRes startConstraintSetId: Int, @IdRes endConstraintSetId: Int, progress: Float)
              if (!didApplyConstraintSet)
              // Let's retrieve our ConstraintSets first
              val startConstraintSet = view.getConstraintSet(startConstraintSetId)
              val endConstraintSet = view.getConstraintSet(endConstraintSetId)
              // Merge them (using an extension function)
              val mergedConstraintSet = startConstraintSet + endConstraintSet
              // Clear + Set them
              endConstraintSet.setConstraints(mergedConstraintSet)
              didApplyConstraintSet = true



              override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int)
              didApplyConstraintSet = false





              To not merge and apply the ConstraintSets each time TransitionListener#onTransitionChange is being called, there's a simple helper variable.



              Lastly, you have to attach the listener to your MotionLayout:



              val accumulativeListener = AccumulativeTransitionListener()
              motionLayout.setTransitionListener(accumulativeListener)


              Let me know if that works or if there are any bugs!






              share|improve this answer

























                1












                1








                1







                As @hoford said, the ConstraintSets are not merged each time they change. Apparently, this is also not possible without using reflection, although it would definitely be useful. Anyway, here is how to do it using reflection (through a few extension functions).



                I did create my own TransitionListener base class to provide support annotations and readable value names.
                The extension functions can be found here.



                What you can do is merge the two ConstraintSets and then mutate the endConstraintSet which can be obtained through TransitionListener#onTransitionChange:



                class AccumulativeTransitionListener: TransitionListener() 

                var didApplyConstraintSet = false

                override fun onTransitionChange(view: MotionLayout, @IdRes startConstraintSetId: Int, @IdRes endConstraintSetId: Int, progress: Float)
                if (!didApplyConstraintSet)
                // Let's retrieve our ConstraintSets first
                val startConstraintSet = view.getConstraintSet(startConstraintSetId)
                val endConstraintSet = view.getConstraintSet(endConstraintSetId)
                // Merge them (using an extension function)
                val mergedConstraintSet = startConstraintSet + endConstraintSet
                // Clear + Set them
                endConstraintSet.setConstraints(mergedConstraintSet)
                didApplyConstraintSet = true



                override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int)
                didApplyConstraintSet = false





                To not merge and apply the ConstraintSets each time TransitionListener#onTransitionChange is being called, there's a simple helper variable.



                Lastly, you have to attach the listener to your MotionLayout:



                val accumulativeListener = AccumulativeTransitionListener()
                motionLayout.setTransitionListener(accumulativeListener)


                Let me know if that works or if there are any bugs!






                share|improve this answer













                As @hoford said, the ConstraintSets are not merged each time they change. Apparently, this is also not possible without using reflection, although it would definitely be useful. Anyway, here is how to do it using reflection (through a few extension functions).



                I did create my own TransitionListener base class to provide support annotations and readable value names.
                The extension functions can be found here.



                What you can do is merge the two ConstraintSets and then mutate the endConstraintSet which can be obtained through TransitionListener#onTransitionChange:



                class AccumulativeTransitionListener: TransitionListener() 

                var didApplyConstraintSet = false

                override fun onTransitionChange(view: MotionLayout, @IdRes startConstraintSetId: Int, @IdRes endConstraintSetId: Int, progress: Float)
                if (!didApplyConstraintSet)
                // Let's retrieve our ConstraintSets first
                val startConstraintSet = view.getConstraintSet(startConstraintSetId)
                val endConstraintSet = view.getConstraintSet(endConstraintSetId)
                // Merge them (using an extension function)
                val mergedConstraintSet = startConstraintSet + endConstraintSet
                // Clear + Set them
                endConstraintSet.setConstraints(mergedConstraintSet)
                didApplyConstraintSet = true



                override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int)
                didApplyConstraintSet = false





                To not merge and apply the ConstraintSets each time TransitionListener#onTransitionChange is being called, there's a simple helper variable.



                Lastly, you have to attach the listener to your MotionLayout:



                val accumulativeListener = AccumulativeTransitionListener()
                motionLayout.setTransitionListener(accumulativeListener)


                Let me know if that works or if there are any bugs!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                jossiwolfjossiwolf

                752515




                752515























                    1














                    Transitions are not delta of state. They go from state to state.
                    ConstraintSets define those states.



                    ConstraintSets (within the context of a MotionScene) define a state which is the base layout + your changes described in the tag.






                    share|improve this answer























                    • OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                      – John O'Reilly
                      2 days ago















                    1














                    Transitions are not delta of state. They go from state to state.
                    ConstraintSets define those states.



                    ConstraintSets (within the context of a MotionScene) define a state which is the base layout + your changes described in the tag.






                    share|improve this answer























                    • OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                      – John O'Reilly
                      2 days ago













                    1












                    1








                    1







                    Transitions are not delta of state. They go from state to state.
                    ConstraintSets define those states.



                    ConstraintSets (within the context of a MotionScene) define a state which is the base layout + your changes described in the tag.






                    share|improve this answer













                    Transitions are not delta of state. They go from state to state.
                    ConstraintSets define those states.



                    ConstraintSets (within the context of a MotionScene) define a state which is the base layout + your changes described in the tag.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 days ago









                    hofordhoford

                    99464




                    99464












                    • OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                      – John O'Reilly
                      2 days ago

















                    • OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                      – John O'Reilly
                      2 days ago
















                    OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                    – John O'Reilly
                    2 days ago





                    OK, so in my case I'll also need to define current layout of View1 (after Transition1) in ConstraintSet for Transitions2 (and also a different ConstraintSet if Transitions1 didn't occur)? My challenge is that we have several transitions changing multiple different views....and there's no guarantee a particular transition has happened before....so permutations grow pretty large (if all combinations of modified View layouts need to be defined for each transition)

                    – John O'Reilly
                    2 days ago

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027526%2fmotionlayout-multiple-cumulative-transitions%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme