滚动时奇怪的webview黑色闪烁

use*_*676 17 android android-webview

我正在从字符串加载数据,并且在我第一次向下滚动webview时闪烁几次.

这是我加载数据的代码:

webview.loadDataWithBaseURL(null, message.getmContent(), "text/html", "UTF-8", null);
Run Code Online (Sandbox Code Playgroud)

和xml:

    <WebView
        android:id="@+id/web_content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer"
        android:layout_below="@id/message_title"
        android:layout_margin="4dp"
         />
Run Code Online (Sandbox Code Playgroud)

use*_*676 32

解决方案是添加:

webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
Run Code Online (Sandbox Code Playgroud)

  • LayerType软件为我创建一个空白的webview.我能找到的最好的解决方案是使用带有Color对象的setBackgroundColor()(重要的,不是int). (5认同)

Vol*_*myr 6

也可以software在 xml 文件中设置图层类型,它对我来说很好用。

android:layerType="software"
Run Code Online (Sandbox Code Playgroud)