Whenever I tried put the default/custom scrollView outside the viewPager the viewPager does not loading at all. I try to set the android:fillViewport="true"
parameter but that does not help at all. Also I use that class https://stackoverflow.com/a/31440577/4776020 and it works, but not 100% correctly. The view on each page in ViewPager is adjusting into the longest one.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:orientation="vertical"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/loadScreenContent" />
<CustomScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CustomViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/screenViewPager" />
</CustomScrollView>
</LinearLayout>
CustomScrollView
public class CustomScrollView extends ScrollView{
private GestureDetector mGestureDetector;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
// Return false if we're scrolling in the x direction
class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}