9

While testing my app on Pixel 3 and Android Pie, I found a weird scroll behavior with a Webview within my app, while scrolling down or up, the scroll is not smooth at all, and sometimes it jumps back to where it was or jumps completely to the top or bottom.

This happens when I swipe up or down (dragging and letting it go)

Here is a quick look of the problem (I was trying to scroll down): https://i.stack.imgur.com/MupYi.jpg

While scrolling down, it moved very slow, it moves so little, and then at the end the scroll jumps to the top a little bit itself.

This is an extended version, the jumps happens (randomly) when the scroll its about to stop and then jumps a little. https://i.stack.imgur.com/bY82h.jpg

I was testing my app with a LG phone and Huawei phone -real devices- (Marshmallow and Nougat), didn't have any problem in any of these devices.

On the emulator I tested a Nexus 5 with Android API 23 (M) and didn't have any problem. But changed the OS on the Nexus 5 to Android Oreo and found the scrolling issue there too.

I thought that the problem was Android Oreo+... but then I tested on the emulator Pixel 3 with Android 23 (M), and have the same scrolling issue. So maybe the device has something to do, but the Android version too.

I've tried to change the layer type like this:

webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)

but doesn't have any effect. the "hardwareAccelerated" tag is true in the Manifest.

The setup of the webview is pretty simple:

<androidx.constraintlayout.widget.ConstraintLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".destinations.common.WebViewDestFragment" android:id="@+id/root_layout">
    <WebView
            android:id="@+id/webView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:overScrollMode="never"
            android:scrollbars="vertical"
            android:fadeScrollbars="false"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    </WebView>
</androidx.constraintlayout.widget.ConstraintLayout>

The settings are also pretty basic:

webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.databaseEnabled = true
webView.settings.cacheMode = LOAD_CACHE_ELSE_NETWORK

Could this be a hardware or android API issue?

Alejandro
  • 325
  • 4
  • 10
  • did you tried to change the android:layout_width="0dp" into android:layout_width="match_parent"? also same with android:layout_height – No Name Aug 13 '19 at 08:03
  • Thx for the reply, just tried that, same issue, do you think ConstraintLayout has something to do? I'll try using LinearLayout. – Alejandro Aug 13 '19 at 08:11
  • I added an answer in this post. Hoping it will help you – No Name Aug 13 '19 at 08:22

1 Answers1

4

Try to change your layout like this

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HomeActivity">

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:overScrollMode="never"/>

</android.support.constraint.ConstraintLayout>

and add this in your java file

if (Build.VERSION.SDK_INT >= 21) {
        webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    //FOR WEBPAGE SLOW UI
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else {
        webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
No Name
  • 472
  • 1
  • 6
  • 19
  • Thanks for your answer, sadly.. same issue , I notice that sometimes it scrolls well, and then scrolls slow again. I'l try a brand new project with just a webview and use this answer, just to make sure the current problem has nothing to do with something in the current project. – Alejandro Aug 13 '19 at 08:45
  • I found you import it somewhere in another layout which is a fragment? Because this is implemented in your code tools:context=".destinations.common.WebViewDestFragment" maybe it has something that makes your scrolling error sometimes. – No Name Aug 13 '19 at 08:57
  • I tried a brand new project (No fragments or anything, just the MainActivity), I just added a webview with the internet permission, and added the settings provided in this answer, same issue. I tested on the emulator with Pixel 3 API 24, 25 and 26, same weird behavior in all these APIs, also Nexus 6 API 24 and same issue, but... tried Nexus 5 API 24 and the scroll works as expected. So I'm starting to believe that is a hardware issue.. – Alejandro Aug 13 '19 at 09:20
  • try to add this in AndroidManifest android:supportsRtl="true" android:hardwareAccelerated="true" android:usesCleartextTraffic="true" – No Name Aug 13 '19 at 09:26
  • and I think it needs to test in the real device or emulator like Nox Player. Because emulator from android studio sometimes not working well. – No Name Aug 13 '19 at 09:29
  • I've tried those changes (supportsRtl, hardwareAccelerated and usesCleartextTraffic) but same result, maybe you're right, it might be a thing from the emulator, as I said in the post I've tested on real devices and had no issues there: LG phone API 23, Huawei API 26 and a tablet with API 24. I've just did a test on Nox Player with Android 7 and had the scroll issue, I'll try to borrow another phones just to confirm that is an issue on the emulators and not on real devices, although, Nox Player did replicate the issue (I don't know if I should trust this emulator or not as a real device). – Alejandro Aug 13 '19 at 10:45
  • 1
    Okay, good to hear that. Hope I helped you in a small way. Happy coding! – No Name Aug 13 '19 at 11:21
  • Exactly the same weird bug happens on a real Sony device (Android 8.1 API 27) and also an emulator device with API 28 on Android studio. Is there any progress on this bug? – alierdogan7 Mar 22 '20 at 21:11