For example I have:
In Kotlin, you can use isDuplicateParentStateEnabled = true before the View is added to the ViewGroup.
As documented in the setDuplicateParentStateEnabled method, if the child view has additional states (like checked state for a checkbox), these won't be affected by the parent.
The xml analogue is android:duplicateParentState="true".