Items of RecyclerView overlap when scrolling during item's animation

Viewed 716

I have a RecyclerView and I've set android:animateLayoutChanges="true" in the item's CardView, because I'm changing its layout from a "visualization mode" to an "edit mode" when I click it. However, if I click the item and then scroll immediately, items will overlap. Basically, the item being animated doesn't respond to the scrolling. If I set android:animateLayoutChanges="false" however, they won't overlap but I will lose the animation.

I've trying things like disabling scrolling while item animates, or simply setting android:animateLayoutChanges="false" and using this.notifyItemChanged(holder.getAdapterPosition()) cause it makes other items on the recycler animate to fill the space properly, but the clicked item itself does not animate.

<android.support.v7.widget.CardView
    android:id="@+id/root_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateLayoutChanges="false"
    android:clickable="true"
    android:elevation="10dp"
    android:focusable="true"
    android:padding="5dp"
    app:cardBackgroundColor="#ffffff"
    app:cardCornerRadius="1dp"
    app:cardUseCompatPadding="true"
    app:contentPadding="5dp">

    <LinearLayout
        android:id="@+id/visualization_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible">
        ...
    </LinearLayout>

    <LinearLayout
        android:id="@+id/editing_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone">
        ...
    </LinearLayout>
</android.support.v7.widget.CardView>`
holder.cardView.setOnClickListener(v -> {        
    holder.visualizationLayout.setVisibility(View.GONE);
    holder.editingLayout.setVisibility(View.VISIBLE);
});

Is there any way to bypass this bad behavior? I would like to keep the animation but without them overlapping.

0 Answers
Related