Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 LinearLayout,里面有一些其他的 LinearLayout。子布局有一个背景选择器集。当按下孩子时,我还需要更改父布局的颜色。我也为父级设置了一个背景选择器,但它仅在单击任何子级之外时触发。
我怎样才能避免这种情况?
谢谢!
尝试将此添加到父 LinearLayout 的布局属性中:
android:addStatesFromChildren="true"
或者,在代码调用中:
parentLayout.setAddStatesFromChildren(true);
在任何一种情况下,请确保子布局没有设置android:duplicateParentState属性(并且不要调用setDuplicateParentState(true)),否则当系统检测到循环依赖时,您将在运行时遇到异常。
android:duplicateParentState
setDuplicateParentState(true)