I have a nested ViewPager that works brilliantly. The only problem is that after the child of the ViewPager is in the last element, and I scroll further, the parent scroll of the ViewPager scrolls. I do not want this behavior.
How do I achieve this?
Here is an example, in my Activity_main.xml I have a parent ViewPager that hosts three fragment pages.
<android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Inside one of the fragment layouts fragment_categories.xml , I have another ViewPager that is a child of the parent viewPager in Activity_main.xml ,
<android.support.v4.view.ViewPager android:id="@+id/mViewPager" android:layout_width="match_parent" android:layout_height="@dimen/offer_height" android:layout_marginTop="2dp" android:overScrollMode="never"/>
Everything works perfectly. But when the child viewPager reaches its last element, and I scroll more, the parent viewPager moves to the next page. I do not want this. I tried to do this by grabbing the touch of the parent ViewPager before, and that didn't work. I assume that I am doing it wrong? (Yes, I changed the tags in xml to com.project.CustomViewPager and tried this.)
CustomViewPager.java :
public CustomViewPager(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if(v != this && v instanceof ViewPager) { return false; } return super.canScroll(v, checkV, dx, x, y); }