2010-08-19 62 views

回答

6

创建HTML模板

String myTable = "<table border=1>" + 
     "<tr>" + 
     "<td>row 1, cell 1</td>" + 
     "<td>row 1, cell 2</td>" + 
     "</tr>" + 
     "<tr>" + 
     "<td>row 2, cell 1</td>" + 
     "<td>row 2, cell 2</td>" + 
     "</tr>" + 
     "</table>"; 

,并加载到你的WebView

myWebView.loadDataWithBaseURL(null, myTable, "text/html", "utf-8", null); 
+1

它工作正常,但问题是我无法使用HTML表格的其他功能,如我想减少行之间的细胞间距,或者我想添加一些颜色到单元格间距称为边框颜色,我无法使用Android。你可以给我示例代码的表格,它看起来和表格中的行和列中的行完全一样。 在此先感谢, – 2010-08-21 18:40:15

+1

在横向模式下文字消失。如果规模较大。无法在webview中进行滚动。任何想法如何在webview中实现滚动 – mainu 2013-08-01 05:17:30

2

它也为我工作:

String tag = "<table border=1>" + 
       "<tr>" + 
        "<td>row 1, cell 1</td>" + 
        "<td>row 1, cell 2</td>" + 
       "</tr>" + 
       "<tr>" + 
        "<td>row 2, cell 1</td>" + 
        "<td>row 2, cell 2</td>" + 
       "</tr>" + 
      "</table>"; 

((WebView) findViewById(R.id.web)).loadData(tag, "text/html", "utf-8"); 
0

我认为这是与Android的问题网络视图在2.2和2.3中。表格标签如宽度,单元格间距和单元格填充在某些Web视图中不受支持,因此不应使用。如果要使用webView.loadData()对表格进行样式设置,请仅使用内联风格标签。

表格边框也应该删除。