網(wǎng)上無(wú)非就是告訴你要加上android:descendantFocusability=”blocksDescendants”
然后就抄來(lái)抄去的萬(wàn)事。
其實(shí)本來(lái)我是拒絕的。
上次看源碼還是7年前。
但是公司最近事情少,實(shí)在無(wú)聊。就點(diǎn)進(jìn)去了解了一下。
private void recoverFocusFromState() {
if (!mPreserveFocusAfterLayout || mAdapter == null || !hasFocus()
|| getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS
|| (getDescendantFocusability() == FOCUS_BEFORE_DESCENDANTS && isFocused())) {
// No-op if either of these cases happens:
// 1. RV has no focus, or 2. RV blocks focus to its children, or 3. RV takes focus
// before its children and is focused (i.e. it already stole the focus away from its
// descendants).
return;
}
可以看到。這里有用到我們的設(shè)置項(xiàng)。
其實(shí)就是不再去檢查子view的焦點(diǎn)。所以直接返回