0

Je dois activer le défilement webview qui est dans le viewpager dans nestescrollview qui est nécessaire parce que j'utilise CollapsingToolbarLayout. Mais je ne peux pas le faire défiler. Tout fonctionne sauf le défilement WebView. Où je me trompe?WebView à l'intérieur ViewPager à l'intérieur de NestedScrollView ne défilant pas verticalement

enter image description here

Voici mon code d'activité:

<?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> 

fragment WebView pour le balisage ViewPager:

<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" /> 

Répondre

3

envelopper votre WebView dans un 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> 

NestedScrollView fonctionne avec CoordinatorLayout et sait comment gérer les défilements correctement.

1

Il suffit d'utiliser fillViewport et layout_behavior 1 fois

<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>