bgogetap / StickyHeaders

Easily add Sticky Headers to your RecyclerView
Apache License 2.0
521 stars 88 forks source link

Crash on StickyLayoutManager.onLayoutChildren #67

Open itshields opened 6 years ago

itshields commented 6 years ago
java.lang.IllegalArgumentException: view is not a child, cannot hide android.support.constraint.ConstraintLayout{bad2621 V.E...C.. .......D 0,2183-1440,2408}
    at android.support.v7.widget.ChildHelper.unhide(ChildHelper.java:352)
    at android.support.v7.widget.RecyclerView$Recycler.getScrapOrHiddenOrCachedHolderForPosition(RecyclerView.java:6098)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5601)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
    at com.brandongogetap.stickyheaders.StickyLayoutManager.onLayoutChildren(StickyLayoutManager.java:83)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3644)
    at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3103)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21046)
    at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:934)
    at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:973)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21046)
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
    at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
    at android.view.View.measure(View.java:21046)
    at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:934)
    at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:973)
    at android.view.View.measure(View.java:21046)
    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1060)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:785)
    at android.view.View.measure(View.java:21046)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2562)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1629)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1878)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
    at android.view.Choreographer.doCallbacks(Choreographer.java:702)
    at android.view.Choreographer.doFrame(Choreographer.java:638)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6692)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
itshields commented 6 years ago

Some additional context, the layout in question contains one RecyclerView with sticky headers in which the adapter provides the dataset via StickyHeaderHandler#getAdapterData and another RecyclerView that does not have sticky headers. One or the other is shown, so the sticky header RecyclerView is sometimes hidden and when hidden findViewById(R.id.header_view).setVisibility = View.GONE is called (and the reverse is called when the view is shown). ConstraintLayout is used as the root layout for the header view holder as well as the root layout of the fragment containing the RecyclerViews (although those are contained in a child FrameLayout within the ConstraintLayout). I do not have a specific repro case for this crash

bgogetap commented 6 years ago

So the layout for the Fragment that contains the RecyclerViews is:

<ConstraintLayout>
  <FrameLayout>
    <RecyclerView>
    <RecyclerView>

?

itshields commented 6 years ago

Sort of. I'm defining the RecyclerViews in separate layouts and including them, and the second RecyclerView layout is more complex, but that one is not the one with sticky headers. Here's a little more detail on the layout hierarchy:

<ConstraintLayout>
    <FrameLayout>
        <include layout=list_1>
        <include layout=list_2>

and then list_1, which is the one with sticky headers, looks like:

<merge>
    <RecyclerView>

and list_2, (no sticky headers) looks like

<ConstraintLayout>
    <LinearLayout>
        <TextView>
        <RecyclerView>
    <View>
    <ScrollView>
        <ConstraintLayout>
            <Custom View (FrameLayout subclass)>
            <RecyclerView>