gpt4 book ai didi

android - View.LAYER_TYPE_HARDWARE 使 NestedScrollView 内的 WebView 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:08:53 27 4
gpt4 key购买 nike

我正在尝试创建一个 WebView,它在滚动时折叠工具栏并隐藏一个 FAB。我的一切正常,但一旦我将 WebView 设置为 View.LAYER_TYPE_HARDWARE,它就会崩溃。崩溃发生在 5.0 及更高版本上。低于 4.4 似乎工作正常。崩溃输出为:

01-14 18:10:09.720 2941-3090/com.webviewtesthw D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-14 18:10:09.796 2941-3090/com.webviewtesthw I/OpenGLRenderer: Initialized EGL, version 1.4
01-14 18:10:09.886 2941-3097/com.webviewtesthw E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
01-14 18:10:10.583 2941-2941/com.webviewtesthw W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2941
01-14 18:10:11.553 2941-2941/com.webviewtesthw W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2941
01-14 18:10:11.727 2941-3090/com.webviewtesthw W/OpenGLRenderer: Layer exceeds max. dimensions supported by the GPU (1088x4288, max=4096x4096)
01-14 18:10:11.728 2941-3090/com.webviewtesthw D/OpenGLRenderer: Current memory usage / total memory usage (bytes):
TextureCache 57600 / 75497472
LayerCache 17825792 / 50331648 (numLayers = 1)
Layer size 1088x4096; isTextureLayer()=0; texid=7 fbo=0; refs=1
Layers total 17825792 (numLayers = 1)
RenderBufferCache 0 / 8388608
GradientCache 40960 / 1048576
PathCache 0 / 33554432
TessellationCache 0 / 1048576
TextDropShadowCache 0 / 6291456
PatchCache 0 / 131072
FontRenderer 0 A8 1048576 / 1048576
FontRenderer 0 RGBA 0 / 0
FontRenderer 0 total 1048576 / 1048576
Other:
FboCache 0 / 0
Total memory usage:
18972928 bytes, 18.09 MB
01-14 18:10:11.729 2941-2941/com.webviewtesthw D/AndroidRuntime: Shutting down VM
01-14 18:10:11.733 2941-2941/com.webviewtesthw E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.webviewtesthw, PID: 2941
java.lang.IllegalStateException: Unable to create layer for WebView
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我的代码如下:

<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.webviewtesthw.ScrollingActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
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="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.webviewtesthw.ScrollingActivity"
tools:showIn="@layout/activity_scrolling">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/webview"></WebView>
</FrameLayout>


</android.support.v4.widget.NestedScrollView>


<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>

</android.support.design.widget.CoordinatorLayout>



package com.webviewtesthw;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ScrollingActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
WebView view = (WebView) findViewById(R.id.webview);
view.setWebViewClient(new WebViewClient());
WebSettings settings = view.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setAppCacheEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setBuiltInZoomControls(true);

settings.setAppCacheEnabled(true);
settings.setAppCachePath(getCacheDir().getAbsolutePath());
settings.setDatabaseEnabled(true);
settings.setSupportMultipleWindows(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setAllowContentAccess(true);
settings.setAllowFileAccess(true);
settings.setSaveFormData(true);
// view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
view.loadUrl("http://vimeo.com");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scrolling, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

我做错了什么?

谢谢。

编辑:如果我将 WebView 的高度和宽度设置为固定大小,那么它可以工作,但是一旦我更改它以匹配父级或包装内容,它就会中断。如果我取出 NestedScrollView

也不会发生此问题

最佳答案

事实证明这是 NestedScrollView 的错误。 https://code.google.com/p/chromium/issues/detail?id=578150

关于android - View.LAYER_TYPE_HARDWARE 使 NestedScrollView 内的 WebView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34802254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com