【问题标题】:WebView inside ViewPager inside NestedScrollView not scrolling verticallyNestedScrollView 内的 ViewPager 内的 WebView 不垂直滚动
【发布时间】:2017-07-11 12:09:39
【问题描述】:

我需要启用放置到 viewpager 中的 webview 滚动,这是必要的,因为我正在使用 CollapsingToolbarLayout。但我不能滚动它。除了 WebView 滚动之外的所有工作。我哪里错了?

这是我的活动标记:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_read_article"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackgroundLight"
    android:fitsSystemWindows="true"
    tools:context="ru.pwrg.revolution.activities.ReadArticleActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorBackgroundDark"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/article_cover"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:srcCompat="@color/colorBackgroundDark" />

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark" />


    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

ViewPager 标记的 WebView 片段:

<WebView android:id="@+id/article_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp"
    xmlns:android="http://schemas.android.com/apk/res/android" />

【问题讨论】:

    标签: android android-viewpager android-webview android-nestedscrollview


    【解决方案1】:

    将您的WebView 包装成NestedScrollView

    <android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <WebView android:id="@+id/article_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp" />
    
    </android.support.v4.widget.NestedScrollView>
    

    NestedScrollViewCoordinatorLayout 一起工作并且知道如何正确处理滚动。

    【讨论】:

      【解决方案2】:

      只需使用fillViewport 和 layout_behavior 1 次

      <android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior">
      
          <android.support.v4.view.ViewPager
              android:id="@+id/pager"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:fillViewport="true"
              app:layout_behavior="@string/appbar_scrolling_view_behavior" />
      
      </android.support.v4.widget.NestedScrollView>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-22
        • 1970-01-01
        • 1970-01-01
        • 2020-05-31
        • 1970-01-01
        • 2017-04-17
        • 1970-01-01
        相关资源
        最近更新 更多