WebView внутри ViewPager внутри NestedScrollView без вертикальной прокрутки

1

Мне нужно включить прокрутку веб-просмотра, помещенную в viewpager, который находится в nestescrollview, что необходимо, потому что я использую CollapsingToolbarLayout. Но я не могу прокрутить его. Все работает, кроме прокрутки WebView. Где я не прав?

Изображение 174551

Вот моя разметка активности:

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

Фрагмент WebView для разметки 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" />
Теги:
android-viewpager
android-webview
android-nestedscrollview

2 ответа

6
Лучший ответ

Оберните ваш 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>

NestedScrollView работает вместе с CoordinatorLayout и знает, как правильно обрабатывать прокрутки.

1

Просто используйте 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>

Ещё вопросы

Сообщество Overcoder
Наверх
Меню