Можно ли анимировать ограниченные изменения высоты вида переработчика при добавлении / удалении элементов? - PullRequest
0 голосов
/ 07 июня 2019

Я хотел бы добиться такого поведения при добавлении или удалении элементов в / из представления переработчика, оно изменяет свою высоту в соответствии с содержимым до указанного значения @dimen/maxRecyclerViewHeight с плавной анимацией.Он работает нормально без анимации после notifyItemInserted/Removed, но представления в представлении рециркулятора «прыгают», что выглядит немного странно.Можно ли как-то этого добиться, используя TransitionManager.beginDelayedTransition(...)?Я ценю любые другие идеи.

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/constraint_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constrainedHeight="true"
        app:layout_constraintHeight_max="@dimen/maxRecyclerViewHeight"/>

    <!-- Other views go under the recycler view -->

</android.support.constraint.ConstraintLayout>

1 Ответ

0 голосов
/ 12 июня 2019

Проведя некоторое исследование, я обнаружил, что этого можно достичь с помощью TransitionManager.

. Предположим, что xml-файл, содержащий макет ограничения с представлением рециркулятора внутри, равен activity_example.xml.Поэтому сразу после вызова notifyItemInserted/notifyItemRemoved и notifyItemRangeChanged вы можете вызвать что-то вроде метода ниже:

private void beginDelayedTransition() {
    final ConstraintSet constraintSet = new ConstraintSet();
    constraintSet.clone(this, R.layout.activity_example);

    // this transition is responsible for animation resizing the view
    final Transition transition = new ChangeBounds(); 
    // or any other duration        
    transition.setDuration(250);

    // constraintLayout is a root layout in the activity_example.xml
    TransitionManager.beginDelayedTransition(constraintLayout, transition);
    constraintSet.applyTo(constraintLayout);
}
...