Мгновенный переход вMotionLayout вместо анимации
В приложении есть TextView и RecyclerView. При скролле RV размер шрифта в TextView должен уменьшаться. Соответственно, и размер самой TextView также должен уменьшаться вместе с размером текста в нём.
Но когда я в XML-файле в Constraints задаю у TextView android:layout_height="wrap_content" в точках start и end, то никакой анимации не происходит. Происходит какой-то мгновенный переход между двумя состояниями. (видео).
И самый непонятный для меня момент - почему, когда я задаю в layout_heightу TextView конкретную величину в dp, получается нормальная плавная анимация (видео)? А как только я задаю wrap_content, то сразу анимация исчезает.
В чём причина такого поведения? Как сделать, чтобы и анимация происходила, и чтобы высота у TextView была wrap_content?
Motion XML:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@id/end"
motion:constraintSetStart="@id/start"
motion:duration="1000">
<OnSwipe motion:touchAnchorId="@+id/rv" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="textSize"
motion:customDimension="18sp" />
</Constraint>
<Constraint
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/textView"
/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/textView"
android:layout_width="match_parent"
android:layout_height="40dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="textSize"
motion:customDimension="12sp" />
</Constraint>
<Constraint
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/textView" />
</ConstraintSet>
</MotionScene>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/activity_main_scene"
tools:context=".MainActivity"
tools:showPaths="true">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/teal_200"
android:text="My friends"
android:textColor="@color/black"
android:textSize="30sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.motion.widget.MotionLayout>