0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Android RecyclerViewが含まれるViewをTransitionでアニメーションしたときに落ちる

Posted at

ちょっと詰まったのでメモです。

RecyclerViewがスクロールしているときにTransitionで親Viewのアニメーションが走るとクラッシュしていた。

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)

スクロール中にアニメーションが走ると同じViewが追加されてしまうようです。

Transition.excludeTarget(R.id.recycler_view, true)でアニメーションからRecyclerViewを除外することで解決しました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?