这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:elevation="2dp"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tab_layout_bg"
app:tabIndicatorColor="@color/tab_indicator_color"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
是在ViewPager中添加填充物的唯一解决方案?
您忘了实现layout_behavior。
在ViewPager属性中,添加
app:layout_behavior="@string/appbar_scrolling_view_behavior"
这是根据Appbar位置缩放视图器高度的原因。
您可能还想看看Cheesesquare,它显示了适当的设置和嵌套滚动的示例。