2013-05-16 120 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