Skip to content

Commit 56a7394

Browse files
committed
add custom attributes and collapsible header
1 parent 03d6294 commit 56a7394

File tree

8 files changed

+78
-15
lines changed

8 files changed

+78
-15
lines changed

15-milky-way/.idea/deploymentTargetDropDown.xml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

15-milky-way/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
An app to learn how to finely customize an animation, using MotionLayout.
44

5-
<!-- <p align="center">
5+
<p align="center">
66
<img src="screenshot.png" style="width:528px;max-width: 100%;">
7-
</p> -->
7+
</p>
88

99
## Features
1010

15-milky-way/app/src/main/java/com/google/samples/motionlayoutcodelab/Step8Activity.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ class Step8Activity : AppCompatActivity() {
3333
}
3434

3535
private fun coordinateMotion() {
36-
// TODO: set progress of MotionLayout based on an AppBarLayout.OnOffsetChangedListener
37-
36+
// set progress of MotionLayout based on an AppBarLayout.OnOffsetChangedListener
37+
val appBarLayout: AppBarLayout = findViewById(R.id.appbar_layout)
38+
val motionLayout: MotionLayout = findViewById(R.id.motion_layout)
39+
val listener = AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
40+
val seekPosition = -verticalOffset / appBarLayout.totalScrollRange.toFloat()
41+
motionLayout.progress = seekPosition
42+
}
43+
appBarLayout.addOnOffsetChangedListener(listener)
3844
}
3945
}

15-milky-way/app/src/main/res/layout/activity_step8.xml

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,39 @@
2828
android:id="@+id/motion_layout"
2929
android:layout_width="match_parent"
3030
android:layout_height="match_parent"
31+
android:minHeight="80dp"
3132
app:layoutDescription="@xml/step8"
33+
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed"
3234
app:motionDebug="SHOW_PATH">
3335

3436
<ImageView
3537
android:id="@+id/background"
3638
android:layout_width="0dp"
3739
android:layout_height="1000dp"
38-
app:layout_constraintTop_toTopOf="parent"
40+
android:scaleType="centerCrop"
3941
app:layout_constraintBottom_toBottomOf="parent"
40-
app:layout_constraintStart_toStartOf="parent"
4142
app:layout_constraintEnd_toEndOf="parent"
43+
app:layout_constraintStart_toStartOf="parent"
44+
app:layout_constraintTop_toTopOf="parent"
4245
app:srcCompat="@drawable/background"
43-
android:scaleType="centerCrop"
4446
tools:ignore="ContentDescription" />
4547

4648

4749
<ImageView
4850
android:id="@+id/moon"
4951
android:layout_width="wrap_content"
5052
android:layout_height="wrap_content"
53+
android:contentDescription="@string/moon"
5154
app:srcCompat="@drawable/ic_moon"
52-
app:tint="?colorOnPrimary"
53-
android:contentDescription="@string/moon" />
55+
app:tint="?colorOnPrimary" />
5456

5557
<TextView
5658
android:id="@+id/credits"
5759
android:layout_width="wrap_content"
5860
android:layout_height="wrap_content"
5961
android:text="@string/credits"
60-
android:textSize="24sp"
61-
android:textColor="?colorOnPrimary" />
62+
android:textColor="?colorOnPrimary"
63+
android:textSize="24sp" />
6264
</androidx.constraintlayout.motion.widget.MotionLayout>
6365
</com.google.android.material.appbar.AppBarLayout>
6466

15-milky-way/app/src/main/res/xml/step5.xml

+19-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,26 @@
4848
motion:percentY="0.6"
4949
/>
5050

51-
<!-- TODO: Add KeyAttributes to rotate and resize @id/moon -->
51+
<!-- rotate and resize @id/moon -->
52+
<KeyAttribute
53+
motion:framePosition="50"
54+
motion:motionTarget="@id/moon"
55+
android:scaleY="2.0"
56+
android:scaleX="2.0"
57+
android:rotation="-360"
58+
/>
59+
<KeyAttribute
60+
motion:framePosition="100"
61+
motion:motionTarget="@id/moon"
62+
android:rotation="-720"
63+
/>
5264

53-
54-
<!-- TODO: Add KeyAttribute to delay the appearance of @id/credits -->
65+
<!-- delay the appearance of @id/credits -->
66+
<KeyAttribute
67+
motion:framePosition="85"
68+
motion:motionTarget="@id/credits"
69+
android:alpha="0.0"
70+
/>
5571

5672
</KeyFrameSet>
5773
</Transition>

15-milky-way/app/src/main/res/xml/step6.xml

+22-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,28 @@
6565
android:alpha="0.0"
6666
/>
6767

68-
<!-- TODO Add Custom attributes here -->
68+
<!-- Custom attributes -->
69+
<KeyAttribute
70+
motion:framePosition="0"
71+
motion:motionTarget="@id/moon">
72+
<CustomAttribute
73+
motion:attributeName="colorFilter"
74+
motion:customColorValue="#FFFFFF" />
75+
</KeyAttribute>
76+
<KeyAttribute
77+
motion:framePosition="50"
78+
motion:motionTarget="@id/moon">
79+
<CustomAttribute
80+
motion:attributeName="colorFilter"
81+
motion:customColorValue="#FFB612" />
82+
</KeyAttribute>
83+
<KeyAttribute
84+
motion:framePosition="100"
85+
motion:motionTarget="@id/moon">
86+
<CustomAttribute
87+
motion:attributeName="colorFilter"
88+
motion:customColorValue="#FFFFFF" />
89+
</KeyAttribute>
6990

7091
</KeyFrameSet>
7192
</Transition>

15-milky-way/app/src/main/res/xml/step7.xml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<OnSwipe
2929
motion:touchAnchorId="@id/moon"
3030
motion:touchAnchorSide="bottom"
31+
motion:dragDirection="dragRight"
3132
/>
3233

3334

15-milky-way/screenshot.png

506 KB
Loading

0 commit comments

Comments
 (0)