I have a NestedScrollView
(NSVchild), inside a horizontal RecyclerView
, inside another NestedScrollView
(NSVparent). Inside NSVchild is a TextView
with long texts.
What I want to know now is, how can I prevent NSVchild from scrolling NSVparent, when NSVchild finishes scrolling from top or bottom?
What I tried:
I tried extending NestedScrollView
, and overriding onTouchEvent
, and returning false when NSVchild is at scroll
0 and user is dragging down on the screen, and when NSVchild is at it's max scroll
and user is dragging up. Returning false
works as expected, but problem is understanding when user is dragging up or down on the screen. here's is the code for that:
float deltaY = 0;
float oldY = 0;
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_MOVE:
float y = ev.getY();
deltaY = y - oldY;
oldY = y;
Log.i("deltaY", deltaY+"");
break;
}
[...]
return super.onTouchEvent(ev);
}
in this approach, deltaY < 0
means that screen is being dragged upwards, and deltaY > 0
means vice versa. It works well as long as there's room for NSVchild to scroll inside itself. when it finishes scrolling from one side, and starts scrolling NSVparent, deltaY
will become less than 0 in one frame, and in the next, more than 0, And this makes my code useless.
Is there any other way to achieve what I want? Or a better way to understand if screen is being dragged up or down?