2009-11-17 104 views
6

我有一個WebView,用於顯示存儲在assets/目錄中的一些HTML /圖像文件。我能夠擁有的WebView負荷的html頁面罰款:WebView無法正確加載資產

mWebView.loadUrl("file:///android_asset/ContentRoot/SubDir/file.html"); 

String data = StaticFunctions.inputStreamToString(getAssets().open("ContentRoot/SubDir/file.html")); 
mWebView.loadDataWithBaseURL("file:///android_asset/ContentRoot/SubDir/file.html", data, "text/html", "UTF-8", null); 

我遇到的問題是,有在HTML類似圖片:

<img src="../Photos/image.jpg" alt="whatever" /> 

而不是從assets/ContentRoot/Photos/image.jpg加載它試圖加載它們從assets/Photos/image.jpg

爲什麼它試圖從錯誤的(相對)位置加載它們,我能做些什麼來糾正這個問題?

回答

0

哦,人......我在這裏錯過了一些愚蠢的東西。該HTML只是平坦的錯誤和Photos目錄是不是從源頭「上」的一個級別。對困惑感到抱歉。

+7

刪除問題!想想成千上萬的失去的靈魂(就像我!),當他們看到'WebView沒有正確加載資產'時,他們的小心臟跳了起來,被正確地回答,只是找到一個無關的非解決方案! – Barney