Как решить проблему с резким изменением высоты у RecyclerView?

У меня в верстке в LinearLayout есть RecyclerView, под которым находится еще один элемент. Проблема заключается в том, что когда в RecyclerView добавляются/удаляются элементы его "физическая" высота меняется мгновенно (ну или просто так выглядит, а причина в другом), хотя (стандартная) анимация еще только началась. Если с добавлением это выглядит терпимо, то при удалении элемента за счет резко изменившейся высоты, элемент, который был под RecyclerView поднимается вверх также резко, в то время как анимация сдвига элементов RecyclerView еще проигрывается => нижний элемент RecyclerView выезжает из под элемента находящегося под RecyclerView. Я знаю только один вариант решения данной проблемы - сделать элемент под RecyclerView его частью, тогда анимация будет работать и на него. Но, на мой взгляд, подобное решение не всегда уместно. Есть ли какой-то иной путь решения данной проблемы?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <EditText
                android:id="@+id/editText_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:hint="Name"
                android:inputType="textMultiLine|textCapSentences"
                android:maxLength="80"
                android:maxLines="2"
                android:paddingLeft="@dimen/margin_base"
                android:paddingTop="@dimen/padding_vertical_edit_text"
                android:paddingRight="@dimen/margin_base"
                android:paddingBottom="@dimen/padding_vertical_edit_text"
                android:textAppearance="@style/TextPrimary" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:text="text"
                android:background="@color/colorPrimary"/>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

Установка менеджера и адаптера

    recyclerSubtasks.setLayoutManager(new LinearLayoutManager(this) {
                    @Override
                    public boolean canScrollVertically() {
                        return false;
                    }
                });
    adapter.setHasStableIds(true);
    recyclerSubtasks.setAdapter(adapter);

Сам адаптер использует SortedList

Разметка элемента списка

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorPrimary">

    <CheckBox
        android:id="@+id/checkbox_done"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginStart="@dimen/margin_base"
        android:button="@drawable/item_check_box" />

    <EditText
        android:id="@+id/editText_subtask"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_base"
        android:background="@color/colorPrimary"
        android:hint="Enter title"
        android:inputType="textMultiLine|textCapSentences"
        android:paddingTop="@dimen/padding_vertical_edit_text"
        android:paddingRight="@dimen/margin_base"
        android:paddingBottom="@dimen/padding_vertical_edit_text"
        android:textAppearance="@style/TextPrimary"
        android:textColor="@color/colorBlack"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/image_cross"
        app:layout_constraintStart_toEndOf="@+id/checkbox_done"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/image_cross"
        android:layout_width="@dimen/size_check_box_icon"
        android:layout_height="@dimen/size_check_box_icon"
        android:layout_marginEnd="@dimen/margin_base"
        android:src="@drawable/cross"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Ответы (1 шт):

Автор решения: Andrew

Попробуйте установить для вашего списка фиксированный размер:

setLayoutManager(new LinearLayoutManager(this))
recyclerSubtasks.hasFixedSize()

и так же установите такой LayoutManager

→ Ссылка