Items of RecyclerView overlap when scrolling during item's animation

早过忘川 提交于 2020-01-05 03:56:13

问题


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 a "edit mode" when I click it. However, if I click the item 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 yo bypass this bad behavior? I would like to keep the animation but without the overlapping.

来源:https://stackoverflow.com/questions/54174688/items-of-recyclerview-overlap-when-scrolling-during-items-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!