[JAVA] Fall when animating a View containing an Android Recycler View with Transition

It's a little jammed, so it's a memo.

When the RecyclerView was scrolling and the parent View animation ran in Transition, it crashed.

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5034)
        at android.view.ViewGroup.addView(ViewGroup.java:4865)
        at android.view.ViewGroup.addView(ViewGroup.java:4805)
        at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:851)
        at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)
        at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8336)
        at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8294)
        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1573)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1331)
        at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1075)
        at android.support.v7.widget.RecyclerView.scrollStep(RecyclerView.java:1832)
        at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5067)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1004)
        at android.view.Choreographer.doCallbacks(Choreographer.java:816)
        at android.view.Choreographer.doFrame(Choreographer.java:748)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:990)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:280)
        at android.app.ActivityThread.main(ActivityThread.java:6710)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

It seems that the same View will be added if the animation runs while scrolling.

The problem was solved by excluding the RecyclerView from the animation with Transition.excludeTarget (R.id.recycler_view, true).

Recommended Posts

Fall when animating a View containing an Android Recycler View with Transition
The basics of the process of making a call with an Android app
[Kotlin / Android] Create a custom view