2011-10-31 131 views
3

我在Android中使用WebView加載一些本地html,將圖像縮放到屏幕作爲背景。但是,當我開始加載WebView的活動時,我會在加載圖像之前獲得一個非常簡短的白屏。這不是一個大問題,但我想避免這個......我試圖將所有相關元素的背景設置爲黑色,但它仍然會發生......任何想法?使用html/css3和WebView將圖像縮放到屏幕上...在圖像加載之前獲取白色屏幕

這裏是我的html:

<!DOCTYPE html> 
<html> 

<head> 
    <meta charset="UTF-8"> 

    <title>NerdRAGE</title> 

    <style> 
     * { margin: 0; padding: 0; } 

     html { 
      background: url(images/10_1.jpg) no-repeat center center fixed; 
      -webkit-background-size: cover; 
      -moz-background-size: cover; 
      -o-background-size: cover; 
      background-size: cover; 
     } 


    </style> 
</head> 

<body bgcolor="#000000"> 



</body> 

</html> 

這裏是我的XML:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#000000" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<WebView 
    android:id="@+id/mapview" 
    android:background="#000000" android:scaleType="centerInside" android:layout_gravity="center_vertical|center_horizontal" android:clickable="false" android:fitsSystemWindows="true" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
    </LinearLayout> 
+0

如果您將'body'和'html'設置爲'background-color:#000000;''會發生什麼? –

+0

相同的結果...不幸的是,我不知道這個問題是在Android還是html/css結尾。 –

+0

是否可以預加載圖像?這可能可以解決問題。 –

回答

0

發現這個職位上的位置:
How to prevent the white 'flash' on page load created by background image loading delay?

嘗試背景色設置爲html元素和刪除body元素上的bgcolor =「#000」內聯樣式(應該避免這種情況,這是不好的做法)。

html {background: #[color] url('images/10_1.jpg') no-repeat center center fixed; } 
+0

即使我在url()之前設置了#000,也沒有工作。在圖像加載之前,它仍然是白屏。將WebView背景設置爲透明也沒有運氣,因爲DOM樹加載了。只是背景還沒有加載,它是白色的。 – Yeung