android recyclerView's view item's onConfigurationChanged is not called

235 Views Asked by At

Has

android:configChanges="orientation|screenSize"

and there are some custom view (root from RelativeLayout), which has

    override fun onConfigurationChanged(newConfig: Configuration?) {
        super.onConfigurationChanged(newConfig)
        // do something to react
    }

the same custom view is used in either scrollView or recyclerView.

in same activity/fragment when place the custom view in the scrollerView its onConfigurationChanged is called when rotate, but place it in the recyclerView the onConfigurationChanged is not called.

The code has no difference except one use scrollView, one use recyclerView. Is it a known behavior? Or how to make the view item's onConfigurationChanged to be called when place it in the recyclerView?

1

There are 1 best solutions below

0
lannyf On

Turns out there is different how the custom view is placed in the parent container. When add to recyclerview view holder, it is wrapped in a FrameLayout first, so one more layer view which seems prevents the custom view's onConfigurationChange getting called (since the custome view is not the direct view in the viewholder).