0

I use this library StackExpandable to add an Expand/Collapse cardViews as a recyclerview item. Expand/Collapse works fine. But the issue I am facing is that when I expand two items and while scrolling, any item goes out of the screen and comes back, stacked card appears as a normal card. I have tried tracking the expand/collapse states. But, this issue is still there. Here's the video of the issue I am facing: https://drive.google.com/file/d/1MEbMvQXRn9jDNTpbDgzQFtBF78LyczrL/view?usp=sharing Please let me know figure out whats happening to the Recyclerview item when it goes out of the screen and how can it be prevented?

This is the RecyclerView item_layout:

<it.fabiosassu.stackexpandableview.StackExpandableView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/verticalStackedCardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:shownElements="3"/>
Jayesh Babu
  • 1,389
  • 2
  • 20
  • 34
  • You probably have to set the state of the MotionLayout during bind. It may require you to wrap that in a view.post() because the state may not stick until it attached. capturing and setting the state is the way to go. – hoford Dec 23 '21 at 21:02
  • thanks for ur comment. But, I didn't get ur point. Could u elaborate more on this..? – Jayesh Babu Dec 24 '21 at 05:19
  • It is difficult to know how much background you have and have know knowledge of StackExpandable. To achieve its performance Recycler view works by recycling the "view" in this case the MotionLayout instances. Typically RecyclerView creates about 3 more MotionLayout instances than fit on the screen. So when a view (in this case MotionLayout) goes off screen it looses its state as it is reused. It is up to the programmer to capture and reload the state as the view is about to be reused. – hoford Dec 25 '21 at 17:56
  • @hoford I am keeping the track of whether the layout is collapsed or not. But this issue happens without calling onBindViewHolder. It just happens – Jayesh Babu Dec 25 '21 at 18:04
  • This is just not enough information to understand what is wrong. – hoford Dec 26 '21 at 22:36
  • @JayeshBabu Hi, have you found the solution? I got this same issue – TesterKtl May 17 '22 at 04:13

0 Answers0