Reputation: 638
In my app, I have a ViewPager
that has different tabs. Each tab is composed only of a RecyclerView
which can be scrolled vertically.
My problem is that when I try to navigate to other tab and swipe left or right, the RecyclerView's
scroll is detected first and instead of going to another tab the RecyclerView
gets scrolled.
I tried following property of recycler view:
rv_home.setNestedScrollingEnabled(false);
that time ViewPager
swipe works as expected But vertical scrolling of recycler view
disabled. What should I do?
Upvotes: 4
Views: 5568
Reputation: 76
rv_home.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.VERTICAL, false);
layoutManager.setAutoMeasureEnabled(true);
rv_home.setNestedScrollingEnabled(false);
rv_home.setLayoutManager(layoutManager);
try this
Upvotes: 6
Reputation: 571
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
}
}
}
}
})
Upvotes: 0
Reputation: 95
Its because you might have taken RecyclerView item as match parent in width. Take that wrap content and it might work for you as well as it worked for me.
Upvotes: 0