Problem
I have a horizontal RecyclerView inside a NestedScrollView that is inside a ViewPager. Now when I try to scroll through the RecyclerView, sometimes it scrolls, but sometimes only the ViewPager scrolls.
Code
What my XML RecyclerView looks like:
<android.support.v7.widget.RecyclerView android:id="@+id/sidescroll" android:layout_below="@+id/movie_more_movies2" android:layout_marginTop="@dimen/material_layout_keylines_horizontal_margin" android:layout_marginBottom="@dimen/material_layout_keylines_horizontal_margin" android:layout_width="match_parent" android:orientation="horizontal" app:layoutManager="android.support.v7.widget.LinearLayoutManager" android:layout_height="wrap_content"/>
What the nested Scroll in which the RecyclerView is located looks like:
<android.support.v4.widget.NestedScrollView android:id="@+id/detail_holder" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" android:descendantFocusability="blocksDescendants" app:layout_behavior="@string/appbar_scrolling_view_behavior" >
And this is the viewpager xml:
<com.mt.moviesiwanttowatch.ui.ViewPagerWithHorizontalRecyclerView android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false" app:layout_behavior="@string/appbar_scrolling_view_behavior" />
I am using this Custom ViewPager:
public class ViewPagerWithHorizontalRecyclerView extends ViewPager { public ViewPagerWithHorizontalRecyclerView(Context context) { super(context); } public ViewPagerWithHorizontalRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev); } @Override protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if(v instanceof RecyclerView){ Log.e("PAGER", "IS"); return false; } else { Log.e("PAGER", "IS NOT " + v.toString()); } return super.canScroll(v, checkV, dx, x, y); } }
My approach
What I have tried so far, as you can see, I wrote a custom ViewPager. I tried to show the ViewPager that it cannot scroll if the scroll comes from RecyclerView. However, this does not work.
Magazines:
This is the log when ViewPager scrolls instead of RecyclerView
> 06-27 17:50:53.506 32362-32362/com.mt.moviesiwanttowatch E/PAGER: IS NOT > com.mt.moviesiwanttowatch.ui.ViewPagerWithHorizontalRecyclerView{c506165 > VFED..... ........ 0,341-1080,1794