android textview中使用fromHtml方法的图像不';我没有出现
我正在尝试使用Html.fromHtml方法在帮助文件中显示图像 这是我的java代码android textview中使用fromHtml方法的图像不';我没有出现,android,html,image,Android,Html,Image,我正在尝试使用Html.fromHtml方法在帮助文件中显示图像 这是我的java代码 TextView tv = (TextView)findViewById(R.id.text); tv.setText(Html.fromHtml(getString(R.string.help), new Html.ImageGetter() { @Override public Drawable getDrawabl
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而不是TextView。尝试以下解决方案: 1) 将您的top_scrollers.png放入资产文件夹 2) 在raw文件夹中创建包含以下内容的_html.html:
<h1>Help</h1>
<p>
<h3>Getting stone price</h3>
<img src="file:///android_asset/top_scrollers.png"/>
</p>
为此,您应该尝试webview。只需在webview中加载htmlform数据,如webview.loadData(Html.fromHtml(getString(R.string.help),“text/Html”,null);
webView.loadDataWithBaseURL("", your_raw_string, "text/html", "utf-8", "");