我在 CoordinatorLayout 中有一个像这样的 viewpager:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
在 viewpager 中,每个 fragment 都是一个 webview。
代码可以运行,但是当我滚动我的 webview 时。屏幕外的 tablayout 不工作。它就在标题处。
更新:
我尝试使用 relativelayout 来满足我的观点,并使用 NestedScrollView 作为 relativelayout 的父级,但 webview 消失了(进度条显示正常)。是bug吗???
这是我的 fragment 布局:
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="300dp">
<ProgressBar
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/progress_bar_states"></ProgressBar>
<com.handmark.pulltorefresh.library.PullToRefreshWebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/pb" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
最佳答案
对于使用 NestedScrollView 时内容不显示的问题,请将“fillViewport”添加到 xml:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
关于android - CoordinatorLayout 中的 ViewPager 然后在屏幕外滚动 tablayout 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31426193/