2010-02-02 159 views
3

我有點尷尬張貼這個,但我似乎無法弄清楚 我哪裏出錯了。我已經看過每個示例和每個 教程,一切看起來都適合我。這是我正在做的。我 有一個列表視圖,當你點擊一個項目,它會帶你到一個 WebView,顯示一些與該 列表條目相關聯的靜態格式文本。WebView顯示黑屏

我已經使用TextView工作,但我希望能夠使用 HTML格式的文本,並認爲WebView是 去的方式。現在它只是爲了顯示 測試目的的通用鏈接,但是當viewContent意圖啓動時,它僅僅是 黑屏。我可以回去選擇另一個條目,它也 只顯示黑屏。

我不確定你想看到什麼代碼,所以這裏是 viewSection類文件和viewsection.xml佈局。

viewSection.java:

import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 

public class viewSection extends Activity { 

     /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     WebView wv; 

     setContentView(R.layout.viewsection); 

     wv = (WebView) findViewById(R.id.wv1); 
     wv.loadData("<a href='x'>Hello World! - 1</a>", 
               "text/html", 
               "utf-8"); 
    } 
} 

viewsection.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <WebView android:id="@+id/wv1" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
     /> 
</LinearLayout> 

回答

2

你可能想設置android:layout_heightWebViewfill_parent。我不確定WebView是否支持wrap_content

編輯:你要的LinearLayout寬度和高度設置爲fill_parent爲好。另外,如果您使用的是非常輕的HTML樣式,您仍然可以使用TextView; API Demos示例應用程序中有關於如何執行此操作的示例(即StyledText.javaLink.java)。

+0

我可能會看樣式文本。改變layout_height並沒有解決它。 有沒有其他想法? – Ian 2010-02-02 02:27:36

+1

請參閱我的編輯:LinearLayout寬度和高度。事實上,你可能甚至不需要一個LinearLayout,只需將WebView放在頂層。 – 2010-02-02 04:31:58

+0

正確。拿出LinearLayout解決了這個問題。謝謝你太多了! – Ian 2010-02-03 04:40:47