問題:單獨(dú)使用RecyclerView實(shí)現(xiàn)瀑布流會出現(xiàn)各種問題嚣艇,如上拉到最頂部出現(xiàn)留白抵皱,或者錯亂等問題丰刊。
解決方案:使用NestedScrollView去嵌套RecyclerView上渴,禁用RecyclerView的滑動吼虎,并使用smartRefresh來控制上拉加載和下拉刷新冯袍。
步驟:
1匈挖、布局
最外層smartRefresh,然后scrollView康愤,最后RecyclerView儡循。記住RecyclerView外層套一層RelativeLayout否則會出現(xiàn)顯示不全的情況。
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/srl_index"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_case_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:overScrollMode="never" />
</RelativeLayout>
</ScrollView>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
2征冷、activity
其余使用方式和此篇內(nèi)容是一致的http://www.reibang.com/p/f9637b10bb8f
也考參考此篇http://www.reibang.com/p/3a3654a29193
//綁定案例列表
fun bindListData() {
rvCaseList = findViewById<RecyclerView>(R.id.rv_case_list)
//初始化案例列表
rvCaseList.layoutManager = StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL)//GridLayoutManager(me, 2)
rvCaseList.adapter = indexAdapter
//點(diǎn)擊item跳轉(zhuǎn)到詳情頁
indexAdapter.setOnItemClickListener { adapter, view, position ->
// var id = adapter.getItem(position) as IndexCaseListData.Data
// var jp = JumpParameter()
// jp.put("id", id.caseId)
jump(PreferDetailActivity::class.java)//jp
}
//設(shè)置模塊的子組件的點(diǎn)擊事件
indexAdapter.addChildClickViewIds(R.id.tv_update, R.id.tv_delete)
//設(shè)置子組件事件監(jiān)聽
indexAdapter.setOnItemChildClickListener { adapter, view, position ->
}
}