在我的应用程序中,我有一个
ViewPager
,它有不同的选项卡。每个选项卡仅由一个可以垂直滚动的RecyclerView
组成。
我的问题是,当我尝试导航到其他选项卡并向左或向右滑动时,首先检测到
RecyclerView's
滚动,而不是转到另一个选项卡,而是滚动 RecyclerView
。
我尝试了回收器视图的以下属性:
rv_home.setNestedScrollingEnabled(false);
当时
ViewPager
滑动按预期工作,但 recycler view
的垂直滚动被禁用。我应该怎么办?
rv_home.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.VERTICAL, false);
layoutManager.setAutoMeasureEnabled(true);
rv_home.setNestedScrollingEnabled(false);
rv_home.setLayoutManager(layoutManager);
试试这个
这是因为您可能已将 RecyclerView 项目作为宽度上的匹配父项。拿走那个包装内容,它可能对你有用,也对我有用。
rootView.nested_scroll.setOnScrollChangeListener(object : NestedScrollView.OnScrollChangeListener {
override fun onScrollChange(
v: NestedScrollView?,
scrollX: Int,
scrollY: Int,
oldScrollX: Int,
oldScrollY: Int
) {
if (v?.getChildAt(v.getChildCount() - 1) != null) {
if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
scrollY > oldScrollY
) {
var visibleItemCount = (recyclerView.layoutManager as LinearLayoutManager).getChildCount()
var totalItemCount = (recyclerView.layoutManager as LinearLayoutManager).getItemCount()
var pastVisiblesItems =
(recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
//Load Your Items Here
}
}
}
}
})