Как добавить прокрутку веб-просмотра в scrollView

У меня есть требование показать несколько элементов в списке и добавить в конце WebView.

Я добавил RecyclerView и WebView и поместил их оба в ScrollView. Это работает нормально, но не показывает прокрутку в веб-просмотре.

Мне нужно, чтобы мой веб-просмотр имел вертикальную прокрутку.

Это мой код.

<ScrollView
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:fillViewport = "true"
    app:layout_constraintBottom_toBottomOf = "parent"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toBottomOf = "@+id/Title"
    >


    <LinearLayout
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:orientation = "vertical"
        >

        <androidx.recyclerview.widget.RecyclerView
            android:id = "@+id/rvMatchday"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            app:layout_constraintBottom_toBottomOf = "parent"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toTopOf = "parent" />

        <WebView
            android:layout_width = "match_parent"
            android:layout_height = "300dp"
            android:layout_gravity = "bottom"
            android:scrollbars = "vertical"
            android:background = "@color/black"
            android:id = "@+id/twitterWebView"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintHorizontal_bias = "0.0"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toBottomOf = "@+id/rvMatchday" />


    </LinearLayout>

</ScrollView>

Затем я создал родительский файл макета и добавил в него макет выше.

<ScrollView
    android:layout_width = "0dp"
    android:layout_height = "0dp"
    android:fillViewport = "true"
    app:layout_constraintBottom_toBottomOf = "parent"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toTopOf = "parent">

   <include layout = "@layout/fragment_match"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent" />

</ScrollView>

Вы пытаетесь использовать NestedScrollView?

Liem Vo 16.03.2019 21:09
0
1
463
3

Ответы 3

Я думаю, вам не нужно использовать представление прокрутки от имени пользователя root, потому что представление переработчика и веб-представление имеют свои собственные эффекты прокрутки. Просто попробуйте с Linear как root

<LinearLayout
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:orientation = "vertical"
    >

    <androidx.recyclerview.widget.RecyclerView
        android:id = "@+id/rvMatchday"
        android:layout_width = "match_parent"
        android:layout_height = "0dp"
        android:layout_weight = "1"
        />

    <WebView
        android:layout_width = "match_parent"
        android:layout_height = "300dp"
        android:background = "@color/black"
        android:id = "@+id/twitterWebView"
       />


</LinearLayout>

Вам не нужно использовать представление прокрутки в файле layout.xml, а также в родительском файле макета. подобно

 <LinearLayout
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:orientation = "vertical">

        <androidx.recyclerview.widget.RecyclerView
            android:id = "@+id/rvMatchday"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            app:layout_constraintBottom_toBottomOf = "parent"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toTopOf = "parent" />

        <WebView
            android:layout_width = "match_parent"
            android:layout_height = "300dp"
            android:layout_gravity = "bottom"
            android:scrollbars = "vertical"
            android:background = "@android:color/black"
            android:id = "@+id/twitterWebView"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintHorizontal_bias = "0.0"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toBottomOf = "@+id/rvMatchday" />
             </LinearLayout>

и родительский макет

    <android.support.constraint.ConstraintLayout
    android:layout_width = "0dp"
    android:layout_height = "0dp"
    android:fillViewport = "true"
    app:layout_constraintBottom_toBottomOf = "parent"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toTopOf = "parent">

    <include layout = "@layout/fragment_match"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent" />

</android.support.constraint.ConstraintLayout>

в вашей деятельности/фрагменте установите веб-просмотр как прокручиваемый

webView.setVerticalScrollBarEnabled(true);

Другие вопросы по теме