Button 屏蔽事件 beforeDescendants 無(wú)效問(wèn)題
昨天下午遇到一個(gè)奇怪的問(wèn)題,需求父類(lèi)View 統(tǒng)一處理事件,屏蔽Button。
父類(lèi)設(shè)置了
android:clickable="true"
android:descendantFocusability="beforeDescendants"
子類(lèi):
android:clickable="false"
按理說(shuō)沒(méi)什么問(wèn)題,結(jié)果就是Button一直相應(yīng)事件。
折騰了許久,沒(méi)有發(fā)現(xiàn)問(wèn)題,終于早上重新找發(fā)現(xiàn)之前用
ButterKnife 給子類(lèi)Button設(shè)置了點(diǎn)擊事件,導(dǎo)致對(duì)該Button的屏蔽沒(méi)有起到作用。
這是應(yīng)該仔細(xì)的地方。
順便回顧下 descendantFocusability 的作用:
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
定義ViewGroup及其后代之間的獲取焦點(diǎn)的順序關(guān)系
beforeDescendants:viewgroup會(huì)優(yōu)先其子類(lèi)控件而獲取到焦點(diǎn)
afterDescendants:viewgroup只有當(dāng)其子類(lèi)控件不需要獲取焦點(diǎn)時(shí)才獲取焦點(diǎn)
blocksDescendants:viewgroup會(huì)覆蓋子類(lèi)控件而直接獲得焦點(diǎn)