This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 175
ViewTransition
John Hoford edited this page Jul 25, 2021
·
10 revisions
ViewTransition is a new tag that enables single view animations within MotionLayout. With ViewTransition you can change a single view within MotionLayout.
<ViewTransition
android:id="@+id/spin_equ"
motion:motionTarget="@+id/button10"
motion:viewTransitionMode="noState"
motion:onStateTransition="actionDown"
motion:duration="600"
motion:pathMotionArc="none"
motion:motionInterpolator="linear"
motion:setsTag="@id/sets_tag_on_done"
motion:clearsTag="@id/clears_tag_on_done"
motion:ifTagSet="@id/only_run_if_set"
motion:ifTagNotSet="@id/only_run_if_not_set"
>
<ConstraintOverride ....>
<CustomAttribute ...\>
</ConstraintOverride>
<KeyFrameSet>
...
</KeyFrameSet>
</ViewTransition>
- id is used for invoking a View Transition with motionLayout.viewTransition(id, view...)
- motionTarget may be used to define the view or collection of views in conjunction with layout_constraintTag
- viewTransitionMode defines 3 major modes of ViewTransition currentState, allStates and noState. (noState runs asynchronously per view)
- onStateTransition allows the ViewTransition on actionDown or actionUp
-
duration duration of the transition in milliseconds (same as
<Transition>
) - transitionDisable allows you to have disabled ViewTransitions which can be enabled with motionLayout.enableViewTransition(id)
- pathMotionArc views move in quarter ellipses (same as )
- motionInterpolator defines how the transition will animate easing (same as )
- setsTag on completion of a ViewTransition on a view it calls view.setTag(id, System.nanoTime)
- clearsTag on completion of a ViewTransition on a view it calls view.setTag(id, null)
- ifTagSet ViewTransition will not run if view.getTag(id) == null
- ifTagNotSet ViewTransition will not run if view.getTag(id) != null
#Eamples
<ViewTransition
android:id="@+id/pop"
motion:onStateTransition="actionDownUp"
motion:motionTarget="@+id/button1"
motion:viewTransitionMode="noState"
motion:duration="300">
<KeyFrameSet>
<KeyAttribute
motion:framePosition="100"
android:scaleX="1.5"
android:scaleY="1.5"
/>
</KeyFrameSet>
</ViewTransition>
This scales the button up when pressed and collapses it when released.