布局文件内容如下:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nest_scrollview"
app:layout_constraintTop_toTopOf="@+id/mes_setting_appBarLayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="mio.kon.yyb.nestedscrollviewbug.ScrollingActivity">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
在Activity中获取到NestedScrollView对象。
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
设置如下属性值即可实现ViewPager中嵌套的Fragment页面的滑动。
scrollView.setFillViewport (true);