Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit a303777

Browse files
committed
Add comments to XML files
1 parent da7d2ad commit a303777

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

ConstraintLayoutExamples/motionlayoutintegrations/src/main/java/com/example/androidstudio/motionlayoutintegrations/CollapsingToolbar.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import androidx.core.view.ViewCompat
1414
import androidx.core.view.WindowInsetsCompat
1515
import com.example.androidstudio.motionlayoutintegrations.databinding.ActivityCollapsingToolbarBinding
1616
import com.google.android.material.appbar.AppBarLayout
17-
import kotlinx.android.synthetic.main.activity_entrance.*
1817

1918
class CollapsingToolbar : AppCompatActivity() {
2019

@@ -50,7 +49,7 @@ class CollapsingToolbar : AppCompatActivity() {
5049
binding.motionLayout.minimumHeight = desiredToolbarHeight + insetTopHeight
5150

5251
// modify the end ConstraintSet to set a guideline at the top and bottom of inset
53-
val endConstraintSet = binding.motionLayout.getConstraintSet(R.id.end)
52+
val endConstraintSet = binding.motionLayout.getConstraintSet(R.id.collapsed)
5453
// this guideline is the bottom of the inset area
5554
endConstraintSet.setGuidelineEnd(R.id.inset, desiredToolbarHeight)
5655
// this guideline is the top of the inset area (top of screen)

ConstraintLayoutExamples/motionlayoutintegrations/src/main/res/layout/activity_entrance.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
<ImageView
1515
android:id="@+id/scrolling_background"
1616
android:layout_width="0dp"
17-
android:layout_height="4478px"
17+
android:layout_height="wrap_content"
1818
android:scaleType="centerCrop"
1919
android:src="@drawable/star_paralax"
2020
app:layout_constraintBottom_toBottomOf="parent"
2121
app:layout_constraintEnd_toEndOf="parent"
2222
app:layout_constraintStart_toStartOf="parent"
23-
tools:ignore="PxUsage" />
23+
/>
2424

2525

2626
<TextView

ConstraintLayoutExamples/motionlayoutintegrations/src/main/res/xml/activity_entrance_scene.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:motion="http://schemas.android.com/apk/res-auto">
55

6-
<ConstraintSet android:id="@+id/Welcome" >
6+
<!-- This animation uses a series of autoprogress between different ConstraintSet to build
7+
keyframes of the animation.
8+
9+
As the animation plays, MotionLayout will display each ConstraintSet in turn.
10+
11+
Each ConstraintSet uses deriveConstraintsFrom the previous constraint set to only specify the
12+
changes needed for the next KeyFrame.
13+
-->
14+
<ConstraintSet android:id="@+id/initial" >
715
<Constraint
816
android:id="@+id/scrolling_background"
917
motion:layout_constraintBottom_toBottomOf="parent"
1018
motion:layout_constraintStart_toStartOf="parent"
1119
motion:layout_constraintEnd_toEndOf="parent"
1220
android:layout_width="0dp"
13-
android:layout_height="4478px"
21+
android:layout_height="wrap_content"
1422
android:alpha="0"
1523
/>
1624
</ConstraintSet>
@@ -172,8 +180,10 @@
172180
android:layout_marginEnd="16dp"
173181
/>
174182
</ConstraintSet>
183+
<!-- Each transition uses animateToEnd to combine a sequence of smaller animations into one
184+
big entrance animation. -->
175185
<Transition
176-
motion:constraintSetStart="@+id/Welcome"
186+
motion:constraintSetStart="@+id/initial"
177187
motion:constraintSetEnd="@+id/empty"
178188
motion:motionInterpolator="linear"
179189
motion:autoTransition="animateToEnd"

ConstraintLayoutExamples/motionlayoutintegrations/src/main/res/xml/collapsing_toolbar.xml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,42 @@
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

55
<Transition
6-
app:constraintSetEnd="@+id/end"
7-
app:constraintSetStart="@id/start"
6+
app:constraintSetEnd="@+id/collapsed"
7+
app:constraintSetStart="@id/expanded"
88
>
99
<KeyFrameSet >
10+
<!-- Hold title in place -->
1011
<KeyPosition
1112
app:motionTarget="@+id/title"
1213
app:framePosition="25"
1314
app:percentX="0.0"
1415
app:percentY=".2" />
16+
<!-- At 55, title should still be in place -->
1517
<KeyPosition
1618
app:motionTarget="@+id/title"
1719
app:framePosition="55"
1820
app:percentX="0" />
21+
<!-- at 75, title is 50% to destination -->
1922
<KeyPosition
2023
app:motionTarget="@+id/title"
2124
app:framePosition="75"
2225
app:percentX=".5" />
26+
<!-- Hide subtitle until 55 -->
2327
<KeyAttribute
2428
app:motionTarget="@+id/subtitle"
2529
app:framePosition="55"
2630
android:alpha="0" />
31+
<!-- Hold subtitle in place until 55 -->
2732
<KeyPosition
2833
app:motionTarget="@+id/subtitle"
2934
app:framePosition="55"
3035
app:percentX="0" />
36+
<!-- at 55, subtitle is 50% to destination -->
3137
<KeyPosition
3238
app:motionTarget="@+id/subtitle"
3339
app:framePosition="75"
3440
app:percentX=".5" />
41+
<!-- "pop" icon out at 35, with some translation to make it visually stay in place -->
3542
<KeyAttribute
3643
app:motionTarget="@+id/icon"
3744
app:framePosition="35"
@@ -40,34 +47,40 @@
4047
android:translationY="30dp"
4148
android:translationX="0dp"
4249
app:curveFit="linear" />
50+
<!-- Don't move icon along curve until 35 -->
4351
<KeyPosition
4452
app:motionTarget="@+id/icon"
4553
app:framePosition="35"
4654
app:percentX="0"
4755
app:percentY="0"
4856
app:curveFit="linear" />
57+
<!-- Between 35 and 36 while icon is not visible, jump icon to it's final location -->
4958
<KeyPosition
5059
app:motionTarget="@+id/icon"
5160
app:framePosition="36"
5261
app:percentX="1"
5362
app:percentY="1"
5463
app:curveFit="linear" />
64+
<!-- Translate icon a bit to make it "fill in" after jump -->
5565
<KeyAttribute
5666
app:motionTarget="@+id/icon"
5767
app:framePosition="36"
5868
android:translationY="-30dp"
5969
android:translationX="20dp"
6070
app:curveFit="linear" />
71+
<!-- Animate the bottomCutSize to 0 -->
6172
<KeyAttribute
6273
app:motionTarget="@id/background"
6374
app:framePosition="60">
6475
<CustomAttribute app:attributeName="bottomCutSize" app:customDimension="0dp" />
6576
</KeyAttribute>
77+
<!-- animate the endCutSize to 200, a little before the end of animation -->
6678
<KeyAttribute
6779
app:motionTarget="@id/background"
6880
app:framePosition="80">
6981
<CustomAttribute app:attributeName="endCutSize" app:customDimension="200dp" />
7082
</KeyAttribute>
83+
<!-- bring the system bar overlay in slightly early (numbers decided visually) -->
7184
<KeyPosition
7285
app:motionTarget="@+id/systembar_overlay"
7386
app:framePosition="45"
@@ -76,7 +89,8 @@
7689
</KeyFrameSet>
7790
</Transition>
7891

79-
<ConstraintSet android:id="@+id/start">
92+
<!-- Start constraint set uses expanded_bottom and parent as bottom and top bounds -->
93+
<ConstraintSet android:id="@+id/expanded">
8094
<Constraint
8195
android:id="@+id/title"
8296
android:layout_width="wrap_content"
@@ -128,7 +142,9 @@
128142
app:layout_constraintEnd_toEndOf="parent" />
129143
</ConstraintSet>
130144

131-
<ConstraintSet android:id="@+id/end" >
145+
<!-- end constraint set uses collapsed_top and parent as top and bottom, with inset as
146+
guideline -->
147+
<ConstraintSet android:id="@+id/collapsed" >
132148
<Constraint
133149
android:id="@+id/title"
134150
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)