布局文件中使用以下代码即可
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <!-- AppBarLayout里放入的都可以跟着向上滑动滑出布局的的, 添加app:layout_scrollFlags="scroll"属性可以滑出布局 TabLayout没有添加,所以停留在顶部 --> <android.support.design.widget.TabLayout android:id="@+id/home_tablayout" android:background="#fff" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@color/colorRedDark" app:tabMode="fixed" app:tabSelectedTextColor="@color/colorOrange" app:tabTextColor="@color/colorGary"> </android.support.design.widget.TabLayout> </android.support.design.widget.AppBarLayout>
另外,如果使用ScrollView要实现ViewPager填充,需要给ScrollView添加一下属性
确保ScrollView可以被子内容填充
android:fillViewport="true"