Button 屏蔽事件 beforeDescendants 無效問題
昨天下午遇到一個奇怪的問題,需求父類View 統(tǒng)一處理事件葛碧,屏蔽Button过吻。
父類設(shè)置了
android:clickable="true"
android:descendantFocusability="beforeDescendants"
子類:
android:clickable="false"
按理說沒什么問題,結(jié)果就是Button一直相應(yīng)事件乳绕。
折騰了許久逼纸,沒有發(fā)現(xiàn)問題,終于早上重新找發(fā)現(xiàn)之前用
ButterKnife 給子類Button設(shè)置了點擊事件,導(dǎo)致對該Button的屏蔽沒有起到作用菠发。
這是應(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及其后代之間的獲取焦點的順序關(guān)系
beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點
afterDescendants:viewgroup只有當(dāng)其子類控件不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點