cachapa / ExpandableLayout

An expandable layout container for Android
Apache License 2.0
2.34k stars 273 forks source link

Using Expandable Layout in Recycler View #56

Open droidluv opened 6 years ago

droidluv commented 6 years ago

Sometimes before closing when the view is scrolled out(fling action) and recycled, the expandable layout bugs out with partially opened view with the height expanded only part way, when calling collapse on that the height doesn't reduce but the views inside disappear.

Also the duration is set as 1000ms.

Also sometimes it won't expand at all, also the expandable area is not a small one like in the example, its around 200dp in height.

Trust-Coder commented 6 years ago

you need to notify the recyclerview that your data is changed so it will reload the updated views. use notifydatasetchanged with the position of item you changed.

droidluv commented 6 years ago

Its not a data issue, the layout fails to collapse, it will be frozen, and I'm not talking about data update here, its like mentioned if I started collapse or expand action and suddenly scrolled with especially a fling action the layout will bug out and the viewholder will hold out a bugged out version of the expandable layout which will be partially collapsed or expanded and on click will hide its content after a delay but won't collapse, the only solution is to prevent user from scrolling until the expand or collapse animation has completed to prevent the layout from bugging out when being recycled.

Trust-Coder commented 6 years ago

alright, its because when you scroll the recyclerview, it automatically removes the scrolled items to save memory and other resources. you should keep a flag with your viewholder to maintain the status of each item. So each time a view is loaded, it will set the state of item according to last time. I built same thing manually last time, so I know the problems here.

in adapter of your recycler view, create an array of booleans to size of your dataset.

expandedPages = new boolean[size];

@Override public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {

if(expandedPages[position])
{
    // set view to expanded
}
else
{
    // set to collapsed for safety
}

}

On Fri, Apr 27, 2018 at 6:48 PM, Sebi Sheldin Sebastian < notifications@github.com> wrote:

Its not a data issue, the layout fails to collapse, it will be frozen, and I'm not talking about data update here, its like mentioned if I started collapse or expand action and suddenly scrolled with especially a fling action the layout will bug out and the viewholder will hold out a bugged out version of the expandable layout which will be partially collapsed or expanded and on click will hide its content after a delay but won't collapse, the only solution is to prevent user from scrolling until the expand or collapse animation has completed to prevent the layout from bugging out when being recycled.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cachapa/ExpandableLayout/issues/56#issuecomment-384975429, or mute the thread https://github.com/notifications/unsubscribe-auth/AhlVzTCDcR2QP1_KX4lbjPAjblgXJEppks5tsyHAgaJpZM4SMJJG .

droidluv commented 6 years ago

I think you're confused with what I am saying, lets make it a bit more clear, if a view holder containing a swipe view layout is getting recycled when its collapsing or expanding (suppose the collapse time is 1 second because the content is large), during that time the swipe view layout has a freeze issue where it will freeze out part way, and nothing, even calling collapse() or expand() makes it animate anymore, but it will hide its content when calling collapse() and make items visible when calling expand() all the time while being partially open.

I am already maintaining saved states to preserve which position(s) needs to be expanded and collapsed

cachapa commented 6 years ago

@droidluv thanks for the report. I've managed to reproduce the issue (or at least a similar issue) on my side. I'll try to issue a fix as soon as possible.

pdadmehr commented 5 years ago

@cachapa, Is it possible to use the Recycler view with 3 levels? Parent, Child, and Grand Child where expanding parent will reveal all of its children and expanding each of those children will reveal theirs?

cachapa commented 5 years ago

@pdadmehr honestly I'm not sure. ExpandableLayout wasn't really designed to be nested since it needs to be able to measure its children so it can size itself.

I think it might work but I'd still recommend against it, as I'm afraid performance wouldn't be great. ExpandableLayout requests layout rebuilds on every frame when expanding or contracting, so its children should be as simple as possible.