【发布时间】:2012-08-25 23:23:23
【问题描述】:
我正在尝试使用 Html.fromHtml 方法在我的帮助文件中显示图像。
这是我的java代码
TextView tv = (TextView)findViewById(R.id.text);
tv.setText(Html.fromHtml(getString(R.string.help), new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int id;
if (source.equals("top_scrollers.png")) {
id = R.drawable.top_scrollers;
}
else if (source.equals("prices.png")) {
id = R.drawable.prices;
}
else if (source.equals("percentage.png")) {
id = R.drawable.percentage;
}
else if (source.equals("mplus.png")) {
id = R.drawable.mplus;
}
else {
return null;
}
Drawable d = getResources().getDrawable(id);
d.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight());
return d;
}
}, null));
这是我的xml
<string name="help">
<![CDATA[
<h1>Help</h1>
<p>
<h3>Getting stone price</h3>
<img src="top_scrollers.png"/>
</p>
]]>
</string>
如您所见,我将图像放置在 cdata 文本中,并且我创建了一种从它们创建可绘制对象的方法,但它只是不可显示。 有什么建议吗?
【问题讨论】:
-
你应该为此尝试 webview。
-
只需在 webview 中加载 htmlform 数据,例如 webview.loadData(Html.fromHtml(getString(R.string.help), "text/html", null);