2013-05-16 118 views
0

我的應用程序中的webview沒有顯示出來。我去互聯網找到答案,但我什麼都沒找到,只是教程如何使用控制。我正在嘗試加載一個html文件,但沒有顯示。Webview不顯示html

我向用戶清單中添加了用戶權限'Internet'。

這裏是我的佈局:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:visibility="visible" > 

     <WebView 
      android:id="@+id/wvInfo" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </TableRow> 
</TableLayout> 

我有我的資產文件夾中的文件, 'filename.html'。

下面的代碼是在OnCreate:

WebView wvinfo = (WebView) findViewById(R.id.wvInfo); 
    wvinfo.loadUrl("file:///android_asset/filename.html"); 

當我打開我的手機上的程序,什麼也不顯示。我也嘗試加載一個url,「http://www.google.com」,但仍然沒有顯示。我很難過。有任何想法嗎?

+0

的本地文件,我會用'loadData(HTML, 「text/html的」,NULL);'。您還可以向我們展示清單或您編輯的部分。 – Gjordis

回答

1

嘗試下面的代碼在你的佈局文件

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 



     <WebView 
      android:id="@+id/wvInfo" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

</TableLayout> 
0

我的猜測是你沒有設置內容onCreate()裏面的佈局。

嘗試像這樣...

setContentView(R.layout.webview_layout);

0

你爲什麼要使用Web視圖表佈局?而是使用線性或相對佈局。

嘗試添加該

WebView wvinfo = (WebView) findViewById(R.id.wvInfo); 
     wvinfo .getSettings().setJavaScriptEnabled(true);   
     wvinfo.loadUrl("file:///android_asset/filename.html"); 

讓我知道,如果它的工作原理。

+0

是否真的有必要將RelativeLayout或LinearLayout作爲Webview的父佈局?我不這麼認爲..... – CRUSADER

+0

@ user2252502:這是沒有必要的.try下面的代碼 Pinki

+0

這是沒有必要的。使用表格行也不太好。所以爲了刪除表格行,我告訴了Praveena所做的。 – Oam