每当我尝试在viewPager之外放置默认/自定义scrollView时,viewPager根本不加载。我尝试设置android:fillViewport="true"
参数,但这根本没有帮助。我也使用那个类https://stackoverflow.com/a/31440577/4776020,它可以工作,但不是100%正确。 ViewPager中每个页面上的视图调整为最长的一个。
<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);
}
}
}