Android RecyclerView 莫名自動滾動問題

在項(xiàng)目開發(fā)過程遇到一個問題,切換布局中某個子view的visibility為gone后,RecyclerView 自己莫名其妙的滾動了一點(diǎn)。通過網(wǎng)上查找發(fā)現(xiàn),這是RecyclerView 搶占焦點(diǎn)導(dǎo)致??梢杂靡韵路绞浇鉀Q:
父布局設(shè)置屬性descendantFocusability 為 blocksDescendants,RecyclerView 設(shè)置 屬性overScrollMode 為never。

<com.xxxxxxxxxxxx.Layout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">

<com.xxxxxxxxxx.view.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never" />

</com.xxxxxxxxxxxx.Layout>

descendantFocusability 屬性有三種屬性值:
1、beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點(diǎn)
2、afterDescendants:viewgroup只有當(dāng)其子類控件不需要獲取焦點(diǎn)時才獲取焦點(diǎn)
3、blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點(diǎn)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容