motion_layout.xml
<androidx.constraintlayout.motion.widget.MotionLayout 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:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutDescription="@xml/motion_scene"
app:showPaths="false"
tools:context=".views.fragments.ScheduledExpandCalFragment">
<LinearLayout
android:id="@+id/calendar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appbar">
<com.github.sundeepk.compactcalendarview.CompactCalendarView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="220dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:compactCalendarBackgroundColor="@color/colorAccent"
app:compactCalendarCurrentDayBackgroundColor="@color/colorPrimaryDark"
app:compactCalendarCurrentDayIndicatorStyle="fill_large_indicator"
app:compactCalendarCurrentSelectedDayBackgroundColor="@color/yellow"
app:compactCalendarCurrentSelectedDayIndicatorStyle="fill_large_indicator"
app:compactCalendarEventIndicatorStyle="small_indicator"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextColor="#fff"
app:compactCalendarTextSize="12sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/scheduled_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/image_margin_end"
android:layout_marginEnd="@dimen/image_margin_end"
android:layout_marginBottom="@dimen/image_margin_end"
android:layout_marginStart="@dimen/date_text_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calendar_layout" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorAccent">
<RelativeLayout
android:id="@+id/cal_tabBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<ImageView
android:id="@+id/expand_cal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/image_margin_end"
android:src="@drawable/ic_menu" />
<TextView
android:id="@+id/date_text"
android:layout_width="match_parent"
android:layout_height="@dimen/date_text_height"
android:layout_marginTop="@dimen/image_margin_end"
android:gravity="center_vertical"
android:paddingStart="@dimen/image_margin_end"
android:layout_toStartOf="@id/expand_cal"
android:layout_marginEnd="5dp"
android:paddingEnd="@dimen/image_margin_end"
android:text=""
android:textAlignment="gravity"
android:textColor="@color/white"
android:textSize="@dimen/date_text_size" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
motion_scence.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:motion="http://schemas.android.com/tools">
<Transition
app:constraintSetStart="@id/start"
app:constraintSetEnd="@id/end"
app:duration="1000">
<OnSwipe
app:touchAnchorId="@+id/scheduled_recyclerview"
app:touchAnchorSide="top"
app:dragDirection="dragUp" />
<OnClick app:target="@id/expand_cal"
app:clickAction="toggle"/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/toolbar">
<PropertySet app:alpha="1"/>
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@id/calendar_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">
</Constraint>
<Constraint android:id="@id/toolbar">
<PropertySet app:alpha="1"/>
</Constraint>
</ConstraintSet>
Код во фрагменте / деятельности
motionLayout.setTransitionListener(new MotionLayout.TransitionListener() {
@Override
public void onTransitionStarted(MotionLayout motionLayout, int i, int i1) {
System.out.println("onTransitionStarted " + i + " i1 " + i1);
}
@Override
public void onTransitionChange(MotionLayout motionLayout, int i, int
i1,floatv) {
System.out.println("onTransitionChange " + i + " i1 " + i1 + " v " + v);
}
@Override
public void onTransitionCompleted(MotionLayout motionLayout, int i) {
System.out.println("onTransitionCompleted " + motionLayout + " int " + i
+ " \n shouldShow " + shouldShow);
}
@Override
public void onTransitionTrigger(MotionLayout motionLayout, int i, boolean b,
float v) {
System.out.println("onTransitionTrigger " + i + " b " + b + " v " + v);
}
});