Animations in Android
  • Introduction
  • About us
  • Basic animations
  • ConstraintLayout: Core concepts
  • I like to move it, move it!
  • Step 1
  • Step 2
  • Step 2: Solution
  • Step 3
  • Step 3: Solution
  • Step 4
  • Step 4: Solution
  • Step 5
  • Step 5: Solution
  • Step 6
  • Step 7
  • Step 7: Solution
  • Step 8
  • Step 8: Solution
  • MotionLayout
  • Party time!
  • Shared element transition
  • Adding a RecyclerView
  • Activity transitions
  • Adding a second Activity
  • Adding the shared element transition
  • You made it!
  • VectorDrawable
  • VectorDrawable: Solution
  • Using the VectorDrawable
  • RecyclerView item animation & self-contained MotionScene
  • Creating a self-contained MotionScene
  • Creating a self-contained MotionScene : Solution
  • Adding animations in the RecyclerView items: Step 1
  • Adding animations in the RecyclerView items: Step 2
  • RecyclerView animations step 2: Solution
  • Physic based animations
  • Implement a spring animation
  • Spring animation: Solution
  • The finish line!
Powered by GitBook
On this page

Step 3: Solution

This is the solution of the previous step

activity_main.xml

This is how your activity_main.xml should look like after you finish Step 3:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity"
    android:background="@color/colorBgDark">

    <android.support.v7.widget.CardView
        android:id="@+id/cardview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:cardBackgroundColor="@color/cardview_light_background"
        app:cardCornerRadius="8dp"
        app:cardElevation="2dp"
        app:contentPadding="16dp"
        app:layout_constraintBottom_toBottomOf="@id/second_bg"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/guideline_horizontal30"
        app:layout_constraintVertical_bias="0.0" >

    </android.support.v7.widget.CardView>

    <View
        android:id="@+id/second_bg"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorBg"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline_horizontal38" />

    <!-- Guidelines --> 
    ... ... ... 

</android.support.constraint.ConstraintLayout>

For most of the layout building I'm using the design mode (and in my opinion you should as well since it's going to be much easier). That means that depending on how you move your views, the original position and many more the attributes that the editor will add can vary a bit. In my CardView for instance there's a app:layout_constraintVertical_bias="0.0" attribute added which you may end up not having; that's fine! Just make sure there are no warnings or errors showing up in the editor and that you're happy with the result.

PreviousStep 3NextStep 4

Last updated 6 years ago