本来打算是用textView来显示带图片的html格式的文本的,但是发现在具体使用中 图片的格式设置比较麻烦
private void setBody(StudyLectureTextDetailCls cls) {
// final String httpHead = cls.getSource_http();
// final String body = cls.getBody();
// mBody.setMovementMethod(ScrollingMovementMethod.getInstance());
// final MyHandler myHandler = new MyHandler(this);
// Thread t = new Thread(new Runnable() {
// Message msg = Message.obtain();
// @Override
// public void run() {
// ImageGetter imageGetter = new ImageGetter() {
//
// @Override
// public Drawable getDrawable(String source) {
// URL url;
// Drawable drawable = null;
// try {
// url = new URL(httpHead+source);
// drawable = Drawable.createFromStream(url.openStream(), null);
drawable.setBounds(0, 0, 1080, 520);
// return drawable;
Bitmap bitmap = Image.createImage(url);
Drawable drawable = new BitmapDrawable(bitmap);
// // int w=bitmap.getWidth(), h=bitmap.getHeight(); 用这个不能进行自动缩放
int w=drawable.getIntrinsicWidth(), h=drawable.getIntrinsicHeight();用这个 画出来的东西比实际的小
drawable.setBounds(0, 0, w, h);
bitmap=null;
return drawable;
drawable.set
BitmapDrawable bd = (BitmapDrawable) drawable;
Bitmap bitmap = bd.getBitmap();
DisplayMetrics dm = StudyLecurePictureAty.this.getResources().getDisplayMetrics();
bitmap.setDensity(dm.densityDpi);
// drawable.setBounds(0, 0, 100,100);
drawable =new BitmapDrawable(bitmap);
// } catch (MalformedURLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// return drawable;
// }
// };
// CharSequence test = Html.fromHtml(body, imageGetter, null);
// msg.what = 0x101;
// msg.obj = test;
// myHandler.sendMessage(msg);
// }
// });
// t.start();
// };
所以直接使用webView来使用,
调用这个方法 webView.loadDataWithBaseURL(cls.getSource_http(), cls.getBody(), "text/html", "utf-8", null);
这里就能达到自己想要的效果了