I want to use MotionLayout for animations without any code, just XML.
When I make a ConstraintSets it works fine, if I use all constraint attributes (like layout_width
, layout_constraintEnd_toEndOf
etc), but I don't change them. Can I use the attributes, which I really change in animation only?
Another question connected to this: can I make a transition from any state? Fоr example I want to manage three case with three buttons. I can do it in six transitions (each state to others), but may be it is possible to make only three ones?
Short answer is yes & mostly.
Long answer...
In a MotionScene CostraitnSets are "derived" from the layout. You can also derive from another ConstraintSet. You can override attributes at various levels of granularity.
Simple:
<ConstraintSet>
<Constraint androdi:id="@+id/a
motion:top_margin="23dp"
...
/>
</ConstraintSet>
Simple only defined Constraint tags override the layout
Sectioned:
<ConstraintSet>
<Constraint androdi:id="@+id/a">
<Layout motion:top_margin="23dp" ...\>
<PropertySet android:alpha="0.3" ...\>
<Transform android:scaleX="1.3" ...\>
<Motion motion:transitionEasing="linear ...\>
</ConstraintSet>
</ConstraintSet>
Only sections are replace if you have a section all layout tags are replaced
ConstraintOverrid:
<ConstraintSet>
<ConstraintOVerride androdi:id="@+id/a"
motion:top_margin="23dp"
android:alpha="0.3"...\>
</ConstraintSet>
</ConstraintSet>
Individual attributes are changed but you cannot use "anchor attributes" such as layout_constraintTop_ToTopOf
Second Question Medium answer: you can transition to any State Typically transition are given to and from
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@id/start"
motion:duration="6000">
<OnClick motion:targetId="@+id/button1" />
You can leave out the motion:constraintSetStart.
<Transition
motion:constraintSetEnd="@+id/end"
motion:duration="6000">
<OnClick motion:targetId="@+id/button1" />
Which will mean on click can go to this state from any state. Even in transition between states! You can see code like this here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With