我的webView开始变得非常糟糕,当我向下滚动时,它突然回到显示在它上面的网站的顶部,并且几天前它运行良好。只需轻轻一按,它就可以毫无问题地下降到网站底部。
我一直在尝试解决此问题,我想它必须在清单中进行以下更改之后才开始:
android:hardwareAccelerated="false"
android:largeHeap="true"
我进行了此更改,因为启动时突然我的应用开始崩溃,并且在网上查看时,我发现将hardwareAccelated设置为false可能是一种解决方案,它使该应用开始正常工作,但是webView受到了影响不好。
这是我在更改hardwareAccelerated =“ true”时从logcat得到的错误:
08-27 04:46:01.722 20554-20554/com.newapp.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.newapp.test, PID: 20554
java.lang.RuntimeException: Canvas: trying to draw too large(139560960bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1420)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.widget.ImageView.onDraw(ImageView.java:1286)
at android.view.View.draw(View.java:18398)
at android.view.View.updateDisplayListIfDirty(View.java:17376)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1964)
at android.view.View.updateDisplayListIfDirty(View.java:17371)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.view.View.updateDisplayListIfDirty(View.java:17371)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.view.View.updateDisplayListIfDirty(View.java:17371)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.view.View.updateDisplayListIfDirty(View.java:17371)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.view.View.updateDisplayListIfDirty(View.java:17371)
at android.view.View.draw(View.java:18160)
at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
at android.view.View.draw(View.java:18401)
at com.android.internal.policy.DecorView.draw(DecorView.java:969)
at android.view.View.updateDisplayListIfDirty(View.java:17376)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:722)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:728)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:836)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3168)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2964)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2552)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
at android.view.Choreographer.doCallbacks(Choreographer.java:734)
at android.view.Choreographer.doFrame(Choreographer.java:670)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
如果您可以告诉我在哪里可以找到该位图,该错误说明,将不胜感激,因为在我的可绘制文件夹中我没有。较大的图像文件是90kb png。
我试图在清单中保留hardwareAccelerated =“ false”,并使用在此找到的解决方案:
if (Build.VERSION.SDK_INT >= 15) {
// chromium, enable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
但它也不起作用。
顺便说一句,我正在使用它来迫使网站加载到webView中:
inner class MyClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
view.loadUrl(url)
return true
}
}
这些是我的网络视图设置:
webView.apply {
settings.javaScriptEnabled = true
settings.setSupportZoom(true)
settings.setBuiltInZoomControls(true)
settings.setDisplayZoomControls(false)
settings.loadWithOverviewMode = true
settings.useWideViewPort = true
webViewClient = MyClient()
}
这是我的webView:
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
预先感谢您的支持。