Android显示textview图
问题描述:
我从网页中检索一些html源代码。当我使用Html.showHtml(htmlSource);
时,它不能正确显示图形。 这里是图的样子在网络上,没有着色:Android显示textview图
Day Date Time Event Location
Fri Sep 27 4:00 PM Practice MSC Yellow
Sun Sep 29 3:00 PM MJBL Game vs Runnin Rebels MSC Yellow
这里是图中的HTML和CSS:
<table class="gymschedule">
<colgroup>
<col />
<col />
<col />
<col />
<col width="10" /> <!-- small! -->
<col />
<col />
</colgroup>
<thead>
<tr>
<td>
<nobr>Fri</nobr>
</td>
<td>
<nobr>Nov 1</nobr>
</td>
<td>
<nobr>4:00 PM</nobr>
</td>
<td>
Practice </td>
<td>
<nobr>MSC Yellow</nobr>
</td>
</tr>
<tr>
<td>
<nobr>Fri</nobr>
</td>
<td>
<nobr>Nov 8</nobr>
</td>
<td>
<nobr>4:00 PM</nobr>
</td>
<td>
Practice </td>
<td>
<nobr>MSC Yellow</nobr>
</td>
</tr>
</tbody>
</table>
我怎么可以在文本或图像显示该图在Android手机上正确查看?
答
Android TextView不支持<table>
标记及其关联的标记。有关TextView支持的HTML标记列表,请参阅here。
要显示此信息,您需要使用WebView。首先,web视图添加到您的布局:
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
然后加载相关的活动表HTML:
String html = "<table> ..... </table>";
WebView webView = (WebView)findViewById(R.id.webView);
webView.loadData(html, "text/html", "utf-8");