天天看點

NestedScrollView嵌套RecycleView發生的小問題

1、解決方法:嵌套滑動不激活。

recycleView.setNestedScrollingEnable(false); 

這樣做有個弊端,RecycleView的item會一次性加載完,不管是否顯示,如果item比較多的話不建議這樣使用布局,如果再有下拉重新整理,這種布局設計是非常糟糕的。

建議:隻使用RecycleView,通過設定item類型來顯示要展示的布局

   比如itemType = 0 填充Banner布局

   itemType = 1 填充菜單布局

   ....等等

2、當NestedScrollView嵌套RecycleView布局由Fragment管理,Fragment切換時會自動滑動到ReycleView的頂部。

解決方法:在NestedScrollView唯一子布局中加入 android:descendantFocusability=“blocksDescendants”

android:descendantFocusability 有三個屬性

優先于子控件擷取焦點

“beforeDescendants"

當子控件不需要焦點時,擷取焦點

”afterDescendants“

覆寫所有子控件擷取焦點

”blocksDescendants“

轉載于:https://www.cnblogs.com/erjia/p/6554607.html