0

I've a view structure like this:

NestedScrollView
    RecyclerView

I've implement pagination. Problem is, that RecyclerView does not work as it should, because of NestedScrollView (all items of recyclerview are binded at once). I solved this with:

@Override
public void onScrollChanged() {
    int loaderItemPosition = mRecyclerView.getChildCount() - 1;
    View view = mNestedScrollView.getChildAt(mNestedScrollView.getChildCount() - 1);
    int diff = (view.getBottom() - (mNestedScrollView.getHeight() + mNestedScrollView.getScrollY()));

    if (diff == 0) {
        mNestedScrollView.scrollTo(0, 0);
        load();
    }
}

Problem is, if user "flicks" (scrolls fast from top to bottom) the scroll pops to bottom list (it can be scrolled to it, would be more correct way of saying). I tried to stop that with mNestedScrollView.scrollTo(0, 0);. The idea was to stop scrolling when load(); is hit. If I scroll slowly, everything works good, but even now, the scroll seems little bit laggy.

Is there a way to stop scrolling when load(); is hit and not allow to scroll past that position (when user flicks)?

MaartinAndroid
  • 1,268
  • 1
  • 14
  • 37
  • why are you using a recyclerview inside a nestedscrollview? – ColdFire Apr 10 '18 at 07:47
  • @A.A Well, there's no other way of achieving Collapsing toolbar and also, it's required but my intended design. – MaartinAndroid Apr 10 '18 at 07:48
  • try disabling the nested scrolling of recyclerview – Zeeshan Shabbir Apr 10 '18 at 07:49
  • @ZeeshanShabbir It's already done. – MaartinAndroid Apr 10 '18 at 07:49
  • For collapsing toolbar there is a component called literally `CollapsingToolbarLayout`.. there is probably a better way to achieve your goal without using such view hierarchy – ColdFire Apr 10 '18 at 07:51
  • check my answer [here](https://stackoverflow.com/a/49633143/886001)..may be you're looking for the same behavior – ColdFire Apr 10 '18 at 07:52
  • @A.A Yes, I'm using `CollapsingToolbarLayout` as my parent. I was more looking for this case work-around. It should not be too hard to programmatically stop scrolling (freeze it once). – MaartinAndroid Apr 10 '18 at 07:52
  • stop scrolling isn't the hard part.. my point is that may be if you review your design you'll avoid the problem all together (and eventually some other problems along the way) – ColdFire Apr 10 '18 at 07:54
  • @A.A I see your point and that might be a good start, but for now, I'm more interested in finding a way on how to freeze a recyclerview at specific position (item). It sounds simple, but I haven't found an elegant solution. – MaartinAndroid Apr 10 '18 at 08:02

1 Answers1

0

Add android:descendantFocusability="blocksDescendants" in your recyclerview. hope this help