github.com/r4md4c
<!-- collapsed_layout.xml -->
<android.support.constraint.ConstraintLayout
android:layout_height="match_parent"
android:id="@+id/body_layout"
android:layout_width="match_parent">
<ImageView
android:id="@+id/hero_image"
android:scaleType="centerCrop"
android:layout_height="192dp"/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image">
<ViewStub
android:id="@+id/viewStub"
android:layout="@layout/explore_stories_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<include
android:layout_width="0dp"
layout="@layout/article_content"
android:layout_height="0dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/deepdive_fab"
app:layout_constraintTop_toBottomOf="@+id/hero_image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image" />
<!-- expanded_layout.xml -->
<android.support.constraint.ConstraintLayout
android:layout_height="match_parent"
android:id="@+id/body_layout"
android:layout_width="match_parent">
<ImageView
android:id="@+id/hero_image"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="372dp"/> <FrameLayout android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image">
<include
android:id="@+id/viewStub"
layout="@layout/explore_stories_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout> <include
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
layout="@layout/article_content_expanded"
android:layout_height="0dp"/> <android.support.design.widget.FloatingActionButton
android:id="@+id/deepdive_fab"
app:layout_constraintTop_toBottomOf="@+id/hero_image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image"/>
... /><!-- expanded_layout.xml -->
<android.support.constraint.ConstraintLayout
android:layout_height="match_parent"
android:id="@+id/body_layout"
android:layout_width="match_parent">
<ImageView
android:id="@+id/hero_image"
android:scaleType="centerCrop"
android:layout_height="372dp"/>
<FrameLayout android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image">
<include
android:id="@+id/viewStub"
layout="@layout/explore_stories_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<include
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
layout="@layout/article_content_expanded"
android:layout_height="0dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/deepdive_fab"
app:layout_constraintTop_toBottomOf="@+id/hero_image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image"/>
... />
<!-- collapsed_layout.xml -->
<android.support.constraint.ConstraintLayout
android:layout_height="match_parent"
android:id="@+id/body_layout"
android:layout_width="match_parent">
<ImageView
android:id="@+id/hero_image"
android:scaleType="centerCrop"
android:layout_height="192dp" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image">
<include
android:id="@+id/viewStub"
layout="@layout/explore_stories_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<include
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
layout="@layout/article_content"
android:layout_height="0dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/deepdive_fab"
app:layout_constraintTop_toBottomOf="@+id/hero_image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/hero_image" />
.../>
void clone (ConstraintLayout constraintLayout)
void clone (Context context, @LayoutResId int constraintLayoutId)
void applyTo (ConstraintLayout constraintLayout)
private val nonExpandedStateConstraintSet by lazy {
ConstraintSet()
}
private val expandedStateConstraintSet by lazy {
ConstraintSet()
}
// Initialize both of the ConstraintSets
nonExpandedStateConstraintSet.clone(bodyLayout)
expandedStateConstraintSet.clone(context, R.layout.expanded_layout)
// When clicking the FAB
private fun applyConstraintSets(expand: Boolean) {
if (expand) {
expandedStateConstraintSet.applyTo(bodyLayout)
} else {
nonExpandedStateConstraintSet.applyTo(bodyLayout)
}
}
private val nonExpandedStateConstraintSet by lazy {
ConstraintSet()
}
private val expandedStateConstraintSet by lazy {
ConstraintSet()
}
// Initialize both of the ConstraintSets
nonExpandedStateConstraintSet.clone(bodyLayout)
expandedStateConstraintSet.clone(context, R.layout.expanded_layout)
// When clicking the Fab
private fun applyConstraintSets(expand: Boolean) {
if (expand) {
expandedStateConstraintSet.applyTo(bodyLayout)
} else {
nonExpandedStateConstraintSet.applyTo(bodyLayout)
}
// Magic Starts Here!
TransitionManager.beginDelayedTransition(bodyLayout)
}
compile "com.andkulikov:transitionseverywhere:1.7.6"Gifs taken from: https://medium.com/@andkulikov/animate-all-the-things-transitions-in-android-914af5477d50
Gif taken from: https://medium.com/@andkulikov/animate-all-the-things-transitions-in-android-914af5477d50
Gifs taken from: https://medium.com/@andkulikov/animate-all-the-things-transitions-in-android-914af5477d50
private val nonExpandedStateConstraintSet by lazy {
ConstraintSet()
}
private val expandedStateConstraintSet by lazy {
ConstraintSet()
}
// Initialize both of the ConstraintSets
nonExpandedStateConstraintSet.clone(bodyLayout)
expandedStateConstraintSet.clone(context, R.layout.expanded_layout)
// When clicking the Fab
private fun applyConstraintSets(expand: Boolean) {
if (expand) {
expandedStateConstraintSet.applyTo(bodyLayout)
} else {
nonExpandedStateConstraintSet.applyTo(bodyLayout)
}
TransitionInflater.from(context)
.inflateTransition(R.transition.custom_transition).apply {
TransitionManager.beginDelayedTransition(bodyLayout, this)
}
}
<!-- custom_transition.xml -->
<?xml version="1.0" encoding="utf-8"?>
<transitionSet
xmlns:app="http://schemas.android.com/apk/res-auto"
app:transitionOrdering="together"
app:duration="600"> <transitionSet>
<changeBounds/>
<changeImageTransform/>
<targets>
<target app:targetId="@+id/hero_image"/>
</targets>
</transitionSet <changeBounds>
<targets>
<target app:excludeId="@+id/hero_image"/>
</targets>
</changeBounds> <recolor>
<targets>
<target app:targetId="@+id/preview_text"/>
<target app:targetId="@+id/hero_text"/>
</targets>
</recolor> <fade>
<targets>
<target app:targetId="@+id/category_text"/>
</targets>
</fade>
<transitionSet>
<fade/>
<slide/>
<targets>
<target app:targetId="@+id/exploreStoriesContent"/>
</targets>
</transitionSet>
... /><!-- custom_transition.xml -->
<?xml version="1.0" encoding="utf-8"?>
<transitionSet
xmlns:app="http://schemas.android.com/apk/res-auto"
app:transitionOrdering="together"
app:duration="600">
<transitionSet>
<changeBounds/>
<changeImageTransform/>
<targets>
<target app:targetId="@+id/hero_image"/>
</targets>
</transitionSet>
<changeBounds>
<targets>
<target app:excludeId="@+id/hero_image"/>
</targets>
</changeBounds>
<recolor>
<targets>
<target app:targetId="@+id/preview_text"/>
<target app:targetId="@+id/hero_text"/>
</targets>
</recolor>
<fade>
<targets>
<target app:targetId="@+id/category_text"/>
</targets>
</fade>
<transitionSet>
<fade/>
<slide/>
<targets>
<target app:targetId="@+id/exploreStoriesContent"/>
</targets>
</transitionSet>
</transitionSet>