SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
Introduction to MotionLayout
on Android
Denis Fodor
Android Engineer
Introduction
How to use MotionLayout
Motion Scene file elements03
02
01
C O N T E N T S
Sample Animation04
Conclusion05
Introduction01
“MotionLayout is a layout type that helps you manage motion
and widget animation in your app. It is a subclass of
ConstraintLayout and builds upon its rich layout capabilities.”
Introduction
• It only works with its direct children
• It does not support nested layout hierarchies
• It does not support activity transitions
Introduction
• Describe transitions between layouts
• Animate layout properties
• Supports seekable transitions and keyframes for
customized transitions
• It is fully declarative and any of its transitions can be
described in an XML file
• It is backwards-compatible to API level 14 (Ice Cream
Sandwich)
Introduction
How to use MotionLayout02
• Add the following dependency to your app’s build.gradle
implementation ‘androidx.constraintlayout:constraintlayout:2.0.0-beta4’
• Or this if you are not using AndroidX:
implementation ‘com.android.support.constraint:constraint-layout:2.0.0-beta4’
How to use MotionLayout
• learning_motion_layout.xml
How to use MotionLayout
• learning_motion_layout.xml
How to use MotionLayout
• Generated learning_motion_layout_scene.xml
How to use MotionLayout
Motion Scene file elements03
• Root element of a motion scene XML file
• It is used to create animations in a declarative way
• The same MotionScene file can be reused and applied to
different layouts
MotionScene
MOTION SCENE FILE ELEMENTS
• It has definitions for each View you want to animate in a
motion sequence
ConstraintSet
MOTION SCENE FILE ELEMENTS
• Specifies the attributes and position of a single View in a
motion sequence
Constraint
MOTION SCENE FILE ELEMENTS
• It contains at least the start and end ConstraintSet
• It describes the changes from the start to the end state
• It can contain OnClick, OnSwipe and KeyFrameSet elements
• More information about Motion Scene file elements can be found in the official
documentation https://developer.android.com/training/constraint-layout/
motionlayout/ref
Transition
MOTION SCENE FILE ELEMENTS
Sample Animation04
Demo
SAMPLE ANIMATION
https://github.com/dfodor/MotionLayoutSample
• This is a multi-step animation
• MotionLayout currently does not have an API for controlled
multi-step transitions
• This animation has 4 ConstraintSets and it handles 3
transitions (some of them will be started programmatically)
• For more complex transitions, with more steps, you can
check an article called Suspending over Views — Example
written by Chris Banes
Sample Animation
• Our layout file activity_music_band_list.xml has the following hierarchy
Sample Animation
// MusicBandListActivity.kt
// ids of the ConstraintSets defined in animated_music_band_item_scene.xml
private val firstSet = R.id.first_set
private val secondSet = R.id.second_set
private val thirdSet = R.id.third_set
private fun animate(
vhValues: MusicBandAdapter.ViewHolderValues,
musicBandModel: MusicBandModel) {
val marginTop =
(vhValues.getThumbnailHeight() * SCALE).toInt() - (iconSize * SCALE / 2).toInt() - margin
animatedView.also {
var set = it.getConstraintSet(firstSet)
set.setMargin(R.id.thumbnail, ConstraintSet.TOP, vhValues.getY())
set.setVisibility(R.id.thumbnail, ConstraintSet.VISIBLE)
set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop)
set.applyTo(it)
set = it.getConstraintSet(secondSet)
set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop)
set.applyTo(it)
set = it.getConstraintSet(thirdSet)
set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop)
set.setMargin(R.id.about_container, ConstraintSet.TOP, marginTop)
set.applyTo(it)
// ...
}
}
// MusicBandListActivity.kt
private fun animate(
vhValues: MusicBandAdapter.ViewHolderValues,
musicBandModel: MusicBandModel) {
animatedView.also {
// ...
with(binding) {
thumbnail.background =
ContextCompat.getDrawable(this@MusicBandListActivity, musicBandModel.drawableId)
name.text = getString(musicBandModel.name)
tags.text = getString(musicBandModel.tags)
description.text = getString(musicBandModel.shortDescriptionStringRes)
aboutText.text = getString(musicBandModel.aboutStringRes)
it.setTransitionListener(transitionAdapter)
// transition is defined in activity_music_band_list_scene.xml
root.transitionToEnd()
it.setTransition(firstSet, secondSet)
it.setTransitionDuration(ANIMATION_DURATION)
it.transitionToState(secondSet)
activeSet = ConstraintSetState.FIRST_TO_SECOND
}
}
}
// MusicBandListActivity.kt
private val transitionAdapter = object : TransitionAdapter() {
@Suppress("NON_EXHAUSTIVE_WHEN")
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
with(animatedView) {
when (activeSet) {
ConstraintSetState.FIRST_TO_SECOND -> {
setTransition(secondSet, thirdSet)
setTransitionDuration(ANIMATION_DURATION)
transitionToState(thirdSet)
activeSet = ConstraintSetState.SECOND_TO_THIRD
}
ConstraintSetState.SECOND_TO_FIRST -> {
binding.root.transitionToStart()
val constraintSet = getConstraintSet(firstSet)
constraintSet.setVisibility(R.id.thumbnail, ConstraintSet.GONE)
constraintSet.applyTo(this)
}
ConstraintSetState.THIRD_TO_SECOND -> {
setTransition(secondSet, firstSet)
setTransitionDuration(ANIMATION_DURATION)
transitionToState(firstSet)
activeSet = ConstraintSetState.SECOND_TO_FIRST
}
}
}
}
// ...
}
Sample Animation
• Result after first transition (firstSet → secondSet)
• All ConstraintSets and Transitions are defined in
animated_music_band_item_scene.xml file
• In the first_set, we are positioning the views, setting the
thumbnail dimension ratio and scale and we are hiding back
arrow.
• In the second_set we have to set the scale type again so it
would not be lost and we need to hide other views
• When the first transition is done, we are immediately ready
to start the second transition (secondSet → thirdSet) in
the onTransitionCompleted callback
Sample Animation
Sample Animation
• Result after second transition (secondSet → thirdSet)
• We are starting from the second_set
• In the third_set, we are making the views visible while
controlling the situation when the animation will be
executed from the end to start state.
• Inside the Transition block, the OnClick action is used to
toggle between second_set and third_set.
Sample Animation
Sample Animation
• Result after third transition (thirdSet →
R.id.fourth_set)
• The last step of the animation is completely defined in the
motion scene file and there is no need to start it
programmatically
• Inside the Transition block, we again have the OnClick
action which is used to toggle between third_set and
fourth_set
• We are using ImageFilterView class to animate image
transition with its crossfade attribute (“i” icon is now “x”
icon)
Sample Animation
Conclusion05
• This presentation provided some general information about
MotionLayout and sample animation with all the pieces put
together
• Even though it’s still in beta, that doesn’t prevent us from
creating beautiful animations
Conclusion
References
• Introduction to MotionLayout (part I) by Nicolas Roard
• Introduction to MotionLayout (part II) by Nicolas Roard
• Introduction to MotionLayout (part III) by Nicolas Roard
• Defining motion paths in MotionLayout by Nicolas Roard
• Complex UI/Animations on Android — featuring MotionLayout by Nikhil Panju
• Do the Loco-MotionLayout: Building Animations with MotionLayout by Michael
Scamell
• Advanced & Practical MotionLayout by Jason Pearson
• The official documentation
Thank you
for listening
😄
If you have any questions feel free to reach out to me at
denis@arsfutura.co

Mais conteúdo relacionado

Semelhante a Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor (Ars Futura)

Tracking my face with matlab ws word format
Tracking my face with matlab ws word formatTracking my face with matlab ws word format
Tracking my face with matlab ws word format
Gaspard Ggas
 
Tracking my face with matlab
Tracking my face with matlabTracking my face with matlab
Tracking my face with matlab
Gaspard Ggas
 
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docxGDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
budbarber38650
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
KevinNemo
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David Ortinau
Xamarin
 

Semelhante a Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor (Ars Futura) (20)

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
Android
AndroidAndroid
Android
 
Invalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your CraniumInvalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your Cranium
 
Make your app dance with MotionLayout
Make your app dance with MotionLayoutMake your app dance with MotionLayout
Make your app dance with MotionLayout
 
Move Into Motion Layout
Move Into Motion LayoutMove Into Motion Layout
Move Into Motion Layout
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in Scilab
 
Lhy tutorial gui(1)
Lhy tutorial gui(1)Lhy tutorial gui(1)
Lhy tutorial gui(1)
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Tracking my face with matlab ws word format
Tracking my face with matlab ws word formatTracking my face with matlab ws word format
Tracking my face with matlab ws word format
 
Tracking my face with matlab
Tracking my face with matlabTracking my face with matlab
Tracking my face with matlab
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
Selenium Interview Questions & Answers
Selenium Interview Questions & AnswersSelenium Interview Questions & Answers
Selenium Interview Questions & Answers
 
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docxGDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
 
What's new in selenium 4
What's new in selenium 4What's new in selenium 4
What's new in selenium 4
 
Android view animation in android-chapter18
Android view animation in android-chapter18Android view animation in android-chapter18
Android view animation in android-chapter18
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Programming-In-Alice.pptx
Programming-In-Alice.pptxProgramming-In-Alice.pptx
Programming-In-Alice.pptx
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David Ortinau
 

Mais de Shift Conference

Mais de Shift Conference (20)

Shift Remote: AI: How Does Face Recognition Work (ars futura)
Shift Remote: AI: How Does Face Recognition Work  (ars futura)Shift Remote: AI: How Does Face Recognition Work  (ars futura)
Shift Remote: AI: How Does Face Recognition Work (ars futura)
 
Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...
Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...
Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...
 
Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...
Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...
Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...
 
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
 
Shift Remote: DevOps: Autodesks research into digital twins for AEC - Kean W...
Shift Remote: DevOps: Autodesks research into digital twins for AEC -  Kean W...Shift Remote: DevOps: Autodesks research into digital twins for AEC -  Kean W...
Shift Remote: DevOps: Autodesks research into digital twins for AEC - Kean W...
 
Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...
Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...
Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...
 
Shift Remote: DevOps: Modern incident management with opsgenie - Kristijan L...
Shift Remote: DevOps: Modern incident management with opsgenie -  Kristijan L...Shift Remote: DevOps: Modern incident management with opsgenie -  Kristijan L...
Shift Remote: DevOps: Modern incident management with opsgenie - Kristijan L...
 
Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)
Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)
Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)
 
Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...
Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...
Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...
 
Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)
Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)
Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)
 
Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)
Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)
Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)
 
Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...
Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...
Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...
 
Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...
Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...
Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...
 
Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...
Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...
Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...
 
Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...
Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...
Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...
 
Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...
Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...
Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...
 
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
 
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
 
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
 
Shift Remote: WEB - The Features of WebXR Beyond Virtual Reality - Ada Rose C...
Shift Remote: WEB - The Features of WebXR Beyond Virtual Reality - Ada Rose C...Shift Remote: WEB - The Features of WebXR Beyond Virtual Reality - Ada Rose C...
Shift Remote: WEB - The Features of WebXR Beyond Virtual Reality - Ada Rose C...
 

Último

Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
shivangimorya083
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 

Último (20)

Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 

Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor (Ars Futura)

  • 1. Introduction to MotionLayout on Android Denis Fodor Android Engineer
  • 2. Introduction How to use MotionLayout Motion Scene file elements03 02 01 C O N T E N T S Sample Animation04 Conclusion05
  • 4. “MotionLayout is a layout type that helps you manage motion and widget animation in your app. It is a subclass of ConstraintLayout and builds upon its rich layout capabilities.” Introduction
  • 5. • It only works with its direct children • It does not support nested layout hierarchies • It does not support activity transitions Introduction
  • 6. • Describe transitions between layouts • Animate layout properties • Supports seekable transitions and keyframes for customized transitions • It is fully declarative and any of its transitions can be described in an XML file • It is backwards-compatible to API level 14 (Ice Cream Sandwich) Introduction
  • 7. How to use MotionLayout02
  • 8. • Add the following dependency to your app’s build.gradle implementation ‘androidx.constraintlayout:constraintlayout:2.0.0-beta4’ • Or this if you are not using AndroidX: implementation ‘com.android.support.constraint:constraint-layout:2.0.0-beta4’ How to use MotionLayout
  • 12. Motion Scene file elements03
  • 13. • Root element of a motion scene XML file • It is used to create animations in a declarative way • The same MotionScene file can be reused and applied to different layouts MotionScene MOTION SCENE FILE ELEMENTS
  • 14. • It has definitions for each View you want to animate in a motion sequence ConstraintSet MOTION SCENE FILE ELEMENTS
  • 15. • Specifies the attributes and position of a single View in a motion sequence Constraint MOTION SCENE FILE ELEMENTS
  • 16. • It contains at least the start and end ConstraintSet • It describes the changes from the start to the end state • It can contain OnClick, OnSwipe and KeyFrameSet elements • More information about Motion Scene file elements can be found in the official documentation https://developer.android.com/training/constraint-layout/ motionlayout/ref Transition MOTION SCENE FILE ELEMENTS
  • 19. • This is a multi-step animation • MotionLayout currently does not have an API for controlled multi-step transitions • This animation has 4 ConstraintSets and it handles 3 transitions (some of them will be started programmatically) • For more complex transitions, with more steps, you can check an article called Suspending over Views — Example written by Chris Banes Sample Animation
  • 20. • Our layout file activity_music_band_list.xml has the following hierarchy Sample Animation
  • 21. // MusicBandListActivity.kt // ids of the ConstraintSets defined in animated_music_band_item_scene.xml private val firstSet = R.id.first_set private val secondSet = R.id.second_set private val thirdSet = R.id.third_set private fun animate( vhValues: MusicBandAdapter.ViewHolderValues, musicBandModel: MusicBandModel) { val marginTop = (vhValues.getThumbnailHeight() * SCALE).toInt() - (iconSize * SCALE / 2).toInt() - margin animatedView.also { var set = it.getConstraintSet(firstSet) set.setMargin(R.id.thumbnail, ConstraintSet.TOP, vhValues.getY()) set.setVisibility(R.id.thumbnail, ConstraintSet.VISIBLE) set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop) set.applyTo(it) set = it.getConstraintSet(secondSet) set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop) set.applyTo(it) set = it.getConstraintSet(thirdSet) set.setMargin(R.id.more_info, ConstraintSet.TOP, marginTop) set.setMargin(R.id.about_container, ConstraintSet.TOP, marginTop) set.applyTo(it) // ... } }
  • 22. // MusicBandListActivity.kt private fun animate( vhValues: MusicBandAdapter.ViewHolderValues, musicBandModel: MusicBandModel) { animatedView.also { // ... with(binding) { thumbnail.background = ContextCompat.getDrawable(this@MusicBandListActivity, musicBandModel.drawableId) name.text = getString(musicBandModel.name) tags.text = getString(musicBandModel.tags) description.text = getString(musicBandModel.shortDescriptionStringRes) aboutText.text = getString(musicBandModel.aboutStringRes) it.setTransitionListener(transitionAdapter) // transition is defined in activity_music_band_list_scene.xml root.transitionToEnd() it.setTransition(firstSet, secondSet) it.setTransitionDuration(ANIMATION_DURATION) it.transitionToState(secondSet) activeSet = ConstraintSetState.FIRST_TO_SECOND } } }
  • 23. // MusicBandListActivity.kt private val transitionAdapter = object : TransitionAdapter() { @Suppress("NON_EXHAUSTIVE_WHEN") override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { with(animatedView) { when (activeSet) { ConstraintSetState.FIRST_TO_SECOND -> { setTransition(secondSet, thirdSet) setTransitionDuration(ANIMATION_DURATION) transitionToState(thirdSet) activeSet = ConstraintSetState.SECOND_TO_THIRD } ConstraintSetState.SECOND_TO_FIRST -> { binding.root.transitionToStart() val constraintSet = getConstraintSet(firstSet) constraintSet.setVisibility(R.id.thumbnail, ConstraintSet.GONE) constraintSet.applyTo(this) } ConstraintSetState.THIRD_TO_SECOND -> { setTransition(secondSet, firstSet) setTransitionDuration(ANIMATION_DURATION) transitionToState(firstSet) activeSet = ConstraintSetState.SECOND_TO_FIRST } } } } // ... }
  • 24. Sample Animation • Result after first transition (firstSet → secondSet)
  • 25. • All ConstraintSets and Transitions are defined in animated_music_band_item_scene.xml file • In the first_set, we are positioning the views, setting the thumbnail dimension ratio and scale and we are hiding back arrow. • In the second_set we have to set the scale type again so it would not be lost and we need to hide other views • When the first transition is done, we are immediately ready to start the second transition (secondSet → thirdSet) in the onTransitionCompleted callback Sample Animation
  • 26. Sample Animation • Result after second transition (secondSet → thirdSet)
  • 27. • We are starting from the second_set • In the third_set, we are making the views visible while controlling the situation when the animation will be executed from the end to start state. • Inside the Transition block, the OnClick action is used to toggle between second_set and third_set. Sample Animation
  • 28. Sample Animation • Result after third transition (thirdSet → R.id.fourth_set)
  • 29. • The last step of the animation is completely defined in the motion scene file and there is no need to start it programmatically • Inside the Transition block, we again have the OnClick action which is used to toggle between third_set and fourth_set • We are using ImageFilterView class to animate image transition with its crossfade attribute (“i” icon is now “x” icon) Sample Animation
  • 31. • This presentation provided some general information about MotionLayout and sample animation with all the pieces put together • Even though it’s still in beta, that doesn’t prevent us from creating beautiful animations Conclusion
  • 32. References • Introduction to MotionLayout (part I) by Nicolas Roard • Introduction to MotionLayout (part II) by Nicolas Roard • Introduction to MotionLayout (part III) by Nicolas Roard • Defining motion paths in MotionLayout by Nicolas Roard • Complex UI/Animations on Android — featuring MotionLayout by Nikhil Panju • Do the Loco-MotionLayout: Building Animations with MotionLayout by Michael Scamell • Advanced & Practical MotionLayout by Jason Pearson • The official documentation
  • 33. Thank you for listening 😄 If you have any questions feel free to reach out to me at denis@arsfutura.co