我有一个 TextView 加载 HTML 内容(也有 img 标签)。我的问题是某些图像太大,因此应用程序崩溃。有什么办法可以让图片都一样大吗?
我的代码示例:
String EntireStire = "<b>" + mItem.title + " </b> <br> <img src='"
+ mItem.photo + "' > " + " <br><small>" + mItem.description
+ " <br> " + mItem.content + "</small>";
noteView.setText(Html.fromHtml(EntireStire, new MyImageGetter(),
null));
noteView.setMovementMethod(LinkMovementMethod.getInstance());
}
return rootView;
}
private class MyImageGetter implements Html.ImageGetter {
@Override
public Drawable getDrawable(String arg0) {
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(
(InputStream) new URL(arg0).getContent(), null, null);
@SuppressWarnings("deprecation")
Drawable drawable = new BitmapDrawable(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
return drawable;
} catch (Exception e) {
Drawable d = getResources().getDrawable(R.drawable.ic_launcher);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
}