Skip to content

Commit f719df2

Browse files
committed
add creating animations and handling drag events
1 parent a8aada6 commit f719df2

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
~ limitations under the License.
1414
-->
1515

16-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
1717
xmlns:app="http://schemas.android.com/apk/res-auto"
1818
android:layout_width="match_parent"
19-
android:layout_height="match_parent">
19+
android:layout_height="match_parent"
20+
app:layoutDescription="@xml/activity_step1_scene">
2021

2122
<ImageView
2223
android:id="@+id/red_star"
2324
android:layout_width="wrap_content"
2425
android:layout_height="wrap_content"
25-
app:srcCompat="@drawable/ic_star_outline"
26-
app:tint="?colorSecondary"
26+
android:layout_margin="30dp"
2727
android:contentDescription="@string/star"
28-
android:layout_margin="30dp" />
28+
app:srcCompat="@drawable/ic_star_outline"
29+
app:tint="?colorSecondary" />
2930

30-
</androidx.constraintlayout.widget.ConstraintLayout>
31+
</androidx.constraintlayout.motion.widget.MotionLayout>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<MotionScene
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:motion="http://schemas.android.com/apk/res-auto">
5+
6+
<Transition
7+
motion:constraintSetEnd="@+id/end"
8+
motion:constraintSetStart="@id/start"
9+
motion:duration="1000">
10+
<KeyFrameSet>
11+
</KeyFrameSet>
12+
<OnClick motion:targetId="@+id/red_star"
13+
motion:clickAction="toggle" />
14+
</Transition>
15+
16+
<ConstraintSet android:id="@+id/start">
17+
<Constraint
18+
android:id="@+id/red_star"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
motion:layout_constraintTop_toTopOf="parent"
22+
motion:layout_constraintStart_toStartOf="parent" />
23+
</ConstraintSet>
24+
25+
<ConstraintSet android:id="@+id/end">
26+
<Constraint
27+
android:id="@+id/red_star"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
motion:layout_constraintEnd_toEndOf="parent"
31+
motion:layout_constraintBottom_toBottomOf="parent" />
32+
</ConstraintSet>
33+
</MotionScene>

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,61 @@
2121
<Transition
2222
motion:constraintSetStart="@+id/start"
2323
motion:constraintSetEnd="@+id/end">
24-
<!-- TODO add OnSwipe tag -->
24+
<OnSwipe motion:touchAnchorId="@id/red_star" />
2525
</Transition>
2626

2727
<!-- Constraints to apply at the start of the animation -->
2828
<ConstraintSet android:id="@+id/start">
29-
<!-- TODO apply starting constraints -->
29+
<Constraint
30+
android:id="@+id/red_star"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
motion:layout_constraintStart_toStartOf="parent"
34+
motion:layout_constraintEnd_toEndOf="parent"
35+
motion:layout_constraintBottom_toBottomOf="parent"/>
36+
<Constraint
37+
android:id="@+id/left_star"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:alpha="0.0"
41+
motion:layout_constraintStart_toStartOf="parent"
42+
motion:layout_constraintEnd_toEndOf="parent"
43+
motion:layout_constraintBottom_toBottomOf="parent"/>
44+
<Constraint
45+
android:id="@+id/right_star"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:alpha="0.0"
49+
motion:layout_constraintStart_toStartOf="parent"
50+
motion:layout_constraintEnd_toEndOf="parent"
51+
motion:layout_constraintBottom_toBottomOf="parent"/>
3052
</ConstraintSet>
3153

3254
<!-- Constraints to apply at the end of the animation -->
3355
<ConstraintSet android:id="@+id/end">
34-
<!-- TODO apply ending constraints -->
56+
<Constraint
57+
android:id="@+id/left_star"
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:alpha="1.0"
61+
motion:layout_constraintHorizontal_chainStyle="packed"
62+
motion:layout_constraintStart_toStartOf="parent"
63+
motion:layout_constraintEnd_toStartOf="@id/red_star"
64+
motion:layout_constraintTop_toBottomOf="@id/credits"/>
65+
<Constraint
66+
android:id="@+id/red_star"
67+
android:layout_width="wrap_content"
68+
android:layout_height="wrap_content"
69+
motion:layout_constraintStart_toEndOf="@id/left_star"
70+
motion:layout_constraintEnd_toStartOf="@id/right_star"
71+
motion:layout_constraintTop_toBottomOf="@id/credits"/>
72+
<Constraint
73+
android:id="@+id/right_star"
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:alpha="1.0"
77+
motion:layout_constraintStart_toEndOf="@id/red_star"
78+
motion:layout_constraintEnd_toEndOf="parent"
79+
motion:layout_constraintTop_toBottomOf="@id/credits"/>
3580
</ConstraintSet>
3681
</MotionScene>

0 commit comments

Comments
 (0)