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
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
add a comment |
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
add a comment |
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
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
android android-motionlayout
edited 2 days ago
John O'Reilly
asked 2 days ago
John O'ReillyJohn O'Reilly
5,69432031
5,69432031
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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!
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
add a comment |
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!
add a comment |
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!
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!
answered yesterday
jossiwolfjossiwolf
752515
752515
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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