SlideShare a Scribd company logo
1 of 24
Download to read offline
MotionLayout
MotionLayout
๏ถ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์„ค์ •์„ ์œ„ํ•œ ConstraintLayout ์„ ์ƒ์†ํ•œ ๋ ˆ์ด์•„์›ƒ
๏ถ ConstraintLayout ์• ๋‹ˆ๋ฉ”์ด์…˜๊ณผ ๋‹ฌ๋ฆฌ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์— ๋”ฐ๋ฅธ ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅ
๏ถ XML ์„ ํ†ตํ•ด ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋ณ„๋„์˜ ์ฝ”๋“œ ์—†์ด ์ •์˜ ๊ฐ€๋Šฅ
๏ถ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์ž‘์„ ์œ„ํ•œ MotionScene ํŒŒ์ผ ํ•„์š”
๏ถ ์ง๊ณ„ Child View ์—๋งŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ•œ๊ณ„์ 
๏ถ Android Support Library ๋˜๋Š” Android X Library ๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ
Android Support Library Android X Library
Min SDK 18โ†‘ 14โ†‘
Dependency
implementation 'com.android.support.constraint:constraint-
layout:2.0.0-beta1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-
beta1'
Refenece
https://developer.android.com/reference/android/support/constraint/
motion/MotionLayout?hl=en
https://developer.android.com/reference/androidx/constraintlayout/m
otion/widget/MotionLayout?hl=en
MotionScene
๏ถ ๋ ˆ์ด์•„์›ƒ์˜ ๋ชจ์…˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•œ XML ํŒŒ์ผ
๏ถ res/xml ๊ฒฝ๋กœ์— ์ €์žฅ
๏ถ ConstraintSet, Transition ๋“ฑ์„ ํฌํ•จ
๏ถ Alpha, Visibility, Rotation ๋“ฑ์˜ ๊ฐ’์„ ์„ค์ •ํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ฐ€๋Šฅ
๏ถ CustomAttribute ๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ •์˜๊ฐ’ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
๏ถ MotionLayout ์— app:layoutDescription ์†์„ฑ์— ์ง€์ •ํ•˜์—ฌ ๋ ˆ์ด์•„์›ƒ๊ณผ ์—ฐ๊ฒฐ
๏ถ MotionScene ์— ์ •์˜๋œ ๋‚ด์šฉ์€ MotionLayout ์— ์ •์˜๋œ ์œ ์‚ฌํ•œ ๋‚ด์šฉ๋ณด๋‹ค ์šฐ์„ ์‹œ ๋จ
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex01_basic_motion"
app:showPaths="true"
tools:context=".ex01basic.Ex01BasicActivity">
<View
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/colorPrimaryRed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
[ activity_ex01_basic.xml ]
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex01_basic_motion"
app:showPaths="true"
tools:context=".ex01basic.Ex01BasicActivity">
<View
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/colorPrimaryRed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
[ activity_ex01_basic.xml ]
์• ๋‹ˆ๋ฉ”์ด์…˜ ๋‚ด์šฉ์„ ๊ธฐ์žฌํ•œ ํŒŒ์ผ ์—ฐ๊ฒฐ
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex01_basic_motion.xml ]
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex01_basic_motion.xml ]
์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘/๋ ์ƒํƒœ๋ฅผ ํฌํ•จํ•œ
ConstraintSet ์„ ๋ช…์‹œ
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex01_basic_motion.xml ]
Swipe ์‹œ ์ถ”์ ํ•˜๋ ค๋Š” ๋Œ€์ƒ Id,
์ถ”์ ํ•˜๋ ค๋Š” ๋ชจ์…˜ ๋ฐฉํ–ฅ,
์ถ”์ ํ•˜๋ ค๋Š” ๋Œ€์ƒ์˜ ์ธก๋ฉด ์ •์˜
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex01. ๊ธฐ๋ณธ์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex01_basic_motion.xml ]
์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘/๋ ์ƒํƒœ๋ฅผ ๋ช…์‹œ
Layout ํŒŒ์ผ์— ๊ธฐ์žฌ๋œ ๋‚ด์šฉ๋ณด๋‹ค ์šฐ์„ ๋˜์–ด ์ ์šฉ
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex02_color_change_motion"
app:showPaths="true"
tools:context=".ex02colorchange.Ex02ColorChangeActivity">
<View
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/colorPrimaryBlack"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex02. ์ƒ‰์ƒ ๋ณ€๊ฒฝ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
[ activity_ex02_color_change.xml ]
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<CustomAttribute
app:attributeName="backgroundColor"
app:customColorValue="@color/colorPrimaryBlack" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<CustomAttribute
app:attributeName="backgroundColor"
app:customColorValue="@color/colorPrimaryRed" />
</Constraint>
</ConstraintSet>
Ex02. ์ƒ‰์ƒ ๋ณ€๊ฒฝ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
[ activity_ex02_color_change.xml ]
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/view"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<CustomAttribute
app:attributeName="backgroundColor"
app:customColorValue="@color/colorPrimaryBlack" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<CustomAttribute
app:attributeName="backgroundColor"
app:customColorValue="@color/colorPrimaryRed" />
</Constraint>
</ConstraintSet>
Ex02. ์ƒ‰์ƒ ๋ณ€๊ฒฝ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
[ activity_ex02_color_change.xml ]
๋ณ€๊ฒฝํ•˜๋ ค๋Š” ์†์„ฑ๋ช…๊ณผ ์†์„ฑ๊ฐ’์„ ์ •์˜
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex03_image_filter_view_motion"
app:showPaths="true"
tools:context=".Ex03ImageFilterView.Ex03ImageFilterViewActivity">
<android.support.constraint.utils.ImageFilterView
android:id="@+id/imageFilterView"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_launcher"
app:altSrc="@drawable/brown"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex03. ์ด๋ฏธ์ง€ ๊ต์ฒด, ์ฑ„๋„ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
[ activity_ex03_image_filter_view.xml ]
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex03_image_filter_view_motion"
app:showPaths="true"
tools:context=".Ex03ImageFilterView.Ex03ImageFilterViewActivity">
<android.support.constraint.utils.ImageFilterView
android:id="@+id/imageFilterView"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_launcher"
app:altSrc="@drawable/brown"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex03. ์ด๋ฏธ์ง€ ๊ต์ฒด, ์ฑ„๋„ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
[ activity_ex03_image_filter_view.xml ]
android:src ๋ฐ app:altSrc ์— ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์œ„ํ•œ ์ด๋ฏธ์ง€ ๋ฆฌ์†Œ์Šค ๋ช…์‹œ
ImageFilterView
- AppCompatImageView ๋ฅผ ์ƒ์†
- ์ฑ„๋„, ๋Œ€๋น„, ์˜จ๋„, ํฌ๋กœ์ŠคํŽ˜์ด๋“œ ๊ฐ’์„ ์กฐ์ ˆ ๊ฐ€๋Šฅ
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex03_image_filter_view_motion"
app:showPaths="true"
tools:context=".Ex03ImageFilterView.Ex03ImageFilterViewActivity">
<android.support.constraint.utils.ImageFilterView
android:id="@+id/imageFilterView"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_launcher"
app:altSrc="@drawable/brown"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex03. ์ด๋ฏธ์ง€ ๊ต์ฒด, ์ฑ„๋„ ์• ๋‹ˆ๋ฉ”์ด์…˜ (Custom Attribute)
android:src ๋ฐ app:altSrc ์— ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์œ„ํ•œ ์ด๋ฏธ์ง€ ๋ฆฌ์†Œ์Šค ๋ช…์‹œ
ImageFilterView
- AppCompatImageView ๋ฅผ ์ƒ์†
- ์ฑ„๋„, ๋Œ€๋น„, ์˜จ๋„, ํฌ๋กœ์ŠคํŽ˜์ด๋“œ ๊ฐ’์„ ์กฐ์ ˆ ๊ฐ€๋Šฅ
<MotionScene>
โ€ฆโ€ฆ
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/imageFilterView"
android:layout_width="120dp"
android:layout_height="120dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<CustomAttribute
app:attributeName="Crossfade"
app:customFloatValue="0" />
<CustomAttribute
app:attributeName="saturation"
app:customFloatValue="0" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/imageFilterView"
android:layout_width="120dp"
android:layout_height="120dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<CustomAttribute
app:attributeName="Crossfade"
app:customFloatValue="1" />
<CustomAttribute
app:attributeName="saturation"
app:customFloatValue="1" />
</Constraint>
</ConstraintSet>
</MotionScene>
[ ex03_image_filter_view_motion.xml ]
Crossfade ๊ฐ’์„ 0 > 1 ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋ ˆ์ด์•„์›ƒ์—์„œ ์ •์˜ํ•œ altSrc ํ‘œ์‹œ
saturation 0 > 1 ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋ ˆ์ด์•„์›ƒ์—์„œ ์ •์˜ํ•œ src ์ฑ„๋„ ๋ณ€๊ฒฝ
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex04_keyframe_motion"
app:showPaths="true"
tools:context=".ex01basic.Ex01BasicActivity">
<View
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/colorPrimaryRed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex04. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ activity_ex04_key_frame.xml ]
<MotionScene>
<Transition>
<OnSwipe/>
<KeyFrameSet>
<KeyPosition
app:keyPositionType="parentRelative"
app:percentX="0.25"
app:framePosition="50"
app:motionTarget="@+id/view"/>
</KeyFrameSet>
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex04. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex04_keyframe_motion.xml ]
<MotionScene>
<Transition>
<OnSwipe/>
<KeyFrameSet>
<KeyPosition
app:keyPositionType="parentRelative"
app:percentX="0.25"
app:framePosition="50"
app:motionTarget="@+id/view"/>
</KeyFrameSet>
</Transition>
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
Ex04. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜
[ ex04_keyframe_motion.xml ]
50ํ”„๋ ˆ์ž„์— ๋ถ€๋ชจ ๋ทฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ 1/4 ์ง€์ ์œผ๋กœ ์ด๋™์‹œํ‚ค๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/ex05_keyframe2_motion"
app:showPaths="true"
tools:context=".ex01basic.Ex01BasicActivity">
<View
android:id="@+id/view"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/colorPrimaryRed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.motion.MotionLayout>
Ex05. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜_2
[ activity_ex05_key_frame2.xml ]
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe />
<KeyFrameSet>
<KeyPosition
app:framePosition="20"
app:keyPositionType="parentRelative"
app:motionTarget="@+id/view"
app:percentX="0.1" />
<KeyPosition
app:framePosition="60"
app:keyPositionType="parentRelative"
app:motionTarget="@+id/view"
app:percentX="0.9" />
<KeyAttribute
android:rotation="360"
android:scaleX="2"
android:scaleY="2"
app:framePosition="50"
app:motionTarget="@+id/view" />
</KeyFrameSet>
</Transition>
โ€ฆโ€ฆ
</MotionScene>
Ex05. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜_2
[ ex05_keyframe2_motion.xml ]
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe />
<KeyFrameSet>
<KeyPosition
app:framePosition="20"
app:keyPositionType="parentRelative"
app:motionTarget="@+id/view"
app:percentX="0.1" />
<KeyPosition
app:framePosition="60"
app:keyPositionType="parentRelative"
app:motionTarget="@+id/view"
app:percentX="0.9" />
<KeyAttribute
android:rotation="360"
android:scaleX="2"
android:scaleY="2"
app:framePosition="50"
app:motionTarget="@+id/view" />
</KeyFrameSet>
</Transition>
โ€ฆโ€ฆ
</MotionScene>
Ex05. ํ‚คํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜_2
[ ex05_keyframe2_motion.xml ]
20, 60ํ”„๋ ˆ์ž„์— ๋ถ€๋ชจ ๋ทฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ 10%, 90% ์ง€์ ์œผ๋กœ ์ด๋™
50ํ”„๋ ˆ์ž„์— ๋ทฐ์˜ ํฌ๊ธฐ๋ฅผ 2๋ฐฐ๋กœ ๋Š˜๋ฆฌ๊ณ , ํšŒ์ „ํ•˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showPaths="true"
tools:context=".ex06collapsingtoolbar.Ex06CollapsingToolbarActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/appbar_height">
<include
layout="@layout/ex06_collapsing_toolbar"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/long_text"
android:textSize="16sp"
android:padding="16dp"
android:lineSpacingMultiplier="1.1"
android:textColor="@color/colorPrimaryBlack"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Ex06. Collapsing Toolbar
[ activity_ex06_collapsing_toolbar.xml ]
package com.mdlicht.zb.motionlayoutexample.ex06collapsingtoolbar
import android.content.Context
import android.support.constraint.motion.MotionLayout
import android.support.design.widget.AppBarLayout
import android.util.AttributeSet
class CollapsibleToolbar
@JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0)
: MotionLayout(context, attrs, defStyleAttr),
AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!!
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
(parent as? AppBarLayout)?.addOnOffsetChangedListener(this)
}
}
Ex06. Collapsing Toolbar
[ CollapsingToolbar.kt ]
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:alpha="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/collapseGuideline" />
<Constraint
android:id="@+id/icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/collapseGuideline" />
</ConstraintSet>
</MotionScene>
Ex06. Collapsing Toolbar
[ ex06_collapsing_toolbar_motion ]
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start" />
<ConstraintSet android:id='@+id/start'>
<Constraint
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:alpha="1.0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/icon"
app:layout_constraintStart_toStartOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/icon" />
<Constraint
android:id="@+id/icon"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toTopOf="@+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
</ConstraintSet>

More Related Content

Similar to Android - Motion Layout

Android ppt.pptx
Android ppt.pptxAndroid ppt.pptx
Android ppt.pptx
PawanDhiwar1
ย 
Android crash course
Android crash courseAndroid crash course
Android crash course
Showmax Engineering
ย 
Presentation in Club AJAX Dallas, 11/1/2011
Presentation in Club AJAX Dallas, 11/1/2011Presentation in Club AJAX Dallas, 11/1/2011
Presentation in Club AJAX Dallas, 11/1/2011
MaxMotovilov
ย 
android layouts
android layoutsandroid layouts
android layouts
Deepa Rani
ย 
android design pattern
android design patternandroid design pattern
android design pattern
Lucas Xu
ย 

Similar to Android - Motion Layout (20)

Motion Layout - Easy animations for everyone
Motion Layout - Easy animations for everyoneMotion Layout - Easy animations for everyone
Motion Layout - Easy animations for everyone
ย 
Exploring CameraX from JetPack
Exploring CameraX from JetPackExploring CameraX from JetPack
Exploring CameraX from JetPack
ย 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
ย 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
ย 
Android Materials Design
Android Materials Design Android Materials Design
Android Materials Design
ย 
Mobile Day - Novedades en Android Oreo
Mobile Day - Novedades en Android OreoMobile Day - Novedades en Android Oreo
Mobile Day - Novedades en Android Oreo
ย 
Android ppt.pptx
Android ppt.pptxAndroid ppt.pptx
Android ppt.pptx
ย 
Compose In Practice
Compose In PracticeCompose In Practice
Compose In Practice
ย 
Android 10
Android 10Android 10
Android 10
ย 
Android crash course
Android crash courseAndroid crash course
Android crash course
ย 
Presentation in Club AJAX Dallas, 11/1/2011
Presentation in Club AJAX Dallas, 11/1/2011Presentation in Club AJAX Dallas, 11/1/2011
Presentation in Club AJAX Dallas, 11/1/2011
ย 
Flex/AS3 Architecture And Dependency Injection Frameworks Overview
Flex/AS3 Architecture And Dependency Injection Frameworks OverviewFlex/AS3 Architecture And Dependency Injection Frameworks Overview
Flex/AS3 Architecture And Dependency Injection Frameworks Overview
ย 
Android Apps Development Basic
Android Apps Development BasicAndroid Apps Development Basic
Android Apps Development Basic
ย 
Android view animation in android-chapter18
Android view animation in android-chapter18Android view animation in android-chapter18
Android view animation in android-chapter18
ย 
Best Practices for Android UI by RapidValue Solutions
Best Practices for Android UI by RapidValue SolutionsBest Practices for Android UI by RapidValue Solutions
Best Practices for Android UI by RapidValue Solutions
ย 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
ย 
Responsive Web Development
Responsive Web DevelopmentResponsive Web Development
Responsive Web Development
ย 
android layouts
android layoutsandroid layouts
android layouts
ย 
BACnet HMI5 - BACnet Touch Panel - BACnet Touch Screen - HMI
BACnet HMI5 - BACnet Touch Panel - BACnet Touch Screen - HMIBACnet HMI5 - BACnet Touch Panel - BACnet Touch Screen - HMI
BACnet HMI5 - BACnet Touch Panel - BACnet Touch Screen - HMI
ย 
android design pattern
android design patternandroid design pattern
android design pattern
ย 

Recently uploaded

Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Marc Lester
ย 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
ย 

Recently uploaded (20)

CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
ย 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...
ย 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
ย 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
ย 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
ย 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
ย 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
ย 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
ย 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
ย 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
ย 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
ย 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
ย 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
ย 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insights
ย 
Abortion Clinic In Johannesburg ](+27832195400*)[ ๐Ÿฅ Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ ๐Ÿฅ Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ ๐Ÿฅ Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ ๐Ÿฅ Safe Abortion Pills in Jo...
ย 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
ย 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
ย 
Abortion Pill Prices Germiston ](+27832195400*)[ ๐Ÿฅ Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ ๐Ÿฅ Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ ๐Ÿฅ Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ ๐Ÿฅ Women's Abortion Clinic in...
ย 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
ย 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
ย 

Android - Motion Layout