作者:840126054贝尔 | 来源:互联网 | 2023-05-18 11:42
问题描述:在一个外包项目中需要用到化学公式,于是决定让需求方使用这个网站latex在线编辑器写好公式,然后把图片提供给我,在数据库中的对应字段嵌入图片文件名称,然后我再显示到text
问题描述:
在一个外包项目中需要用到化学公式,于是决定让需求方使用这个网站
latex在线编辑器写好公式,然后把图片提供给我,在数据库中的对应字段嵌入图片文件名称,然后我再显示到textView里面去。
比如一个题目内容为 “文字#/1.gif#文字#/2.gif#”;就表示里面嵌入了两个公式图片。
private void HTML() {
String IMG_PATH = Environment.getExternalStorageDirectory().getPath();
/**
* 此处设计很多字符串的处理,图片的文件名称用两个#包含,在第一个#后面加/以表示它是图片
* 而不是文字
* */
String question = "文字#/1.gif#文字#/2.gif#";
String[] tokens = question.split("#", 0);
StringBuilder html = new StringBuilder();
for (int i = 0; i
if (tokens[i].charAt(0) == '/')
html.append("
+ IMG_PATH+ tokens[i] + "\"/>");
else {
html.append(tokens[i]);
}
TextView tvHTML = (TextView) findViewById(R.id.tvHTML);
Log.i("HTML", html+"");
tvHTML.setText(Html.fromHtml(html+"", imageGetter, null));
}
final Html.ImageGetter imageGetter = new Html.ImageGetter() {
public Drawable getDrawable(String source) {
Drawable drawable = null;
drawable = Drawable.createFromPath(source);
if (null != drawable)
drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 3, drawable.getIntrinsicHeight() * 3);
Log.e("getDrawable", source);
return drawable;
}
};