Search code examples
androidkotlinandroid-recyclerviewlayouttransition

How to set layoutTransition to animate correctly when item is removed from recycle view


I want the transition happens after item is removed from the list however when I remove the item transition happens earlier and it covers other items as shown in the GIF below. my second issue is that when I use layoutTransition, when the fragment is created it expands with animation, how to avoid this at the beginning. my layout is like like this:

<androidx.core.widget.NestedScrollView
  android:id="@+id/scroll_view"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:animateLayoutChanges="true"
  android:fillViewport="true" >

    <androidx.constraintlayout.widget.ConstraintLayout
     android:id="@+id/constraintlayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:animateLayoutChanges="true"
     >
        
          <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

and in the Fragment:(Kotlin):

scroll_view.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
scroll_view.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)
constraintlayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
constraintlayout.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)

but nothing changes, always same behavior

example


Solution

  • I found a way to fix the issue by using custom layout manager :D the layout manager I used : https://github.com/BelooS/ChipsLayoutManager