2013-06-26 59 views
16

當我從字符串中加載數據,就當我向下滾動網頁視圖第一次閃爍幾次閃爍。奇怪的WebView黑色滾動

這是我的代碼,其中我加載數據:

webview.loadDataWithBaseURL(null, message.getmContent(), "text/html", "UTF-8", null); 

和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" 
     /> 
+0

你把你的網頁視圖滾動視圖內?如果是,請嘗試刪除滾動視圖。 –

+0

嘗試機器人:聚焦=假 –

+0

然後設置機器人:scrollingCache = 「假」 –

回答

30

該溶液中加入:

webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); 
+0

webview.getSettings()setRenderPriority(WebSettings.RenderPriority.HIGH);已在API級別18中棄用。http://stackoverflow.com/a/23896233/684582 –

+2

LayerType軟件會爲我生成一個空白的webview。我能找到的最佳解決方案是使用setBackgroundColor()和Color對象(重要的,不是int)。 – Mdlc

+0

* setRenderPriority()*方法已在API級別18中棄用。 不建議調整線程優先級,並且在將來的版本中不支持此方法。 – anivaler

1

用上述溶液解析後,我的WebView autoFocused向下滾動。 我解決了閃爍和自動滾動方式:

webView.setFocusable(false); 
webView.setFocusableInTouchMode(false); 
0

從緩存

webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
webview.loadUrl(Your URL To Load); 
+0

你讀過這個問題嗎? – user1940676

+0

在使用LOAD_NO_CACHE我得到一點延遲加載,當我們使用這是ListView的是每次重新創建視圖無法正常工作,避免閃爍,所以我用這個LOAD_CACHE_ELSE_NETWORK解決問題..我也曾經有過相同的問題眨眼在列表視圖中使用的webview –

+0

您是否嘗試過在listview中添加android:cacheColorHint =「@ null」 ? – user1940676

1

加載數據,它也可以設置在XML文件中software層類型,它爲我工作得很好。

android:layerType="software" 
+0

這是唯一的解決方案,爲我工作,沒有缺點。 –