Reputation: 1
My Recyclerview
item occupies the whole screen height and width.
I wish to implement a custom scroll
inside the Recyclerview
such that it scrolls only one item at a time ( similar to News In Shorts
app ).
Thanks in advance!!
Upvotes: 0
Views: 1570
Reputation: 443
You need to add just two below Lines
RecylerView mRecylerView = (RecylerView).findViewById(R.id.mRecylerView)
SnapHelper mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(mRecylerView);
SnapHelper can be used to snap the child to any imaginary point or any pixel on the screen
Upvotes: 4
Reputation: 3103
Try this code
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Upvotes: 0