【发布时间】:2019-12-19 18:11:40
【问题描述】:
在 Pixel 3 和 Android Pie 上测试我的应用时,我发现我的应用中的 Webview 出现奇怪的滚动行为,向下或向上滚动时,滚动根本不流畅,有时会跳回原来的位置或完全跳到顶部或底部。
当我向上或向下滑动(拖动然后放开)时会发生这种情况
这里是问题的快速浏览(我试图向下滚动): https://imgur.com/a/8acgfCx
向下滚动时,它移动得很慢,它移动得很少,然后滚动到最后自己跳到顶部一点。
这是一个扩展版本,当滚动即将停止然后稍微跳跃时,跳跃(随机)发生。 https://imgur.com/a/K0N0utK
我正在使用 LG 手机和华为手机-真实设备-(棉花糖和牛轧糖)测试我的应用,在这些设备中都没有任何问题。
在模拟器上,我使用 Android API 23 (M) 测试了 Nexus 5,没有遇到任何问题。但是将 Nexus 5 上的操作系统更改为 Android Oreo,也发现了滚动问题。
我以为问题出在 Android Oreo+... 但后来我在带有 Android 23 (M) 的模拟器 Pixel 3 上进行了测试,并且遇到了同样的滚动问题。所以也许设备有问题,但安卓版本也有。
我尝试像这样更改图层类型:
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
但没有任何作用。 Manifest 中的“hardwareAccelerated”标签为真。
webview 的设置非常简单:
<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>
设置也很基本:
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.databaseEnabled = true
webView.settings.cacheMode = LOAD_CACHE_ELSE_NETWORK
这可能是硬件或 Android API 问题吗?
【问题讨论】:
-
您是否尝试将 android:layout_width="0dp" 更改为 android:layout_width="match_parent"?也与 android:layout_height 相同
-
谢谢回复,刚试了下,同样的问题,你觉得ConstraintLayout有什么问题吗?我会尝试使用 LinearLayout。
-
我在这篇文章中添加了一个答案。希望对你有帮助
标签: android scroll android-webview smooth-scrolling bounce