我的目标是在 imageView 中显示一些带有图像的 html。所以我创建了一个 webview,我在位图中转换了这个 webview,并用位图设置了这个 imageview,但是我有一个白屏。我检查了位图不为空。
你知道为什么我有一个白屏吗?也许有更好的方法来做到这一点..?
ImageViewActivity.java
public class ImageViewActivity extends Activity {
private WebView webView;
ImageView imageView;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_view);
webView = (WebView) findViewById(R.id.webView1);
imageView = (ImageView) findViewById(R.id.imageView1);
webView.getSettings().setJavaScriptEnabled(true);
String customHtml = "<div style=\"background-image:url(pic_10.jpg);height:100%;background-repeat:no-repeat;\"><div style=\"position: absolute; bottom: 0; width: 100%\">
HBase 管理手册
www.amazon.com"; webView.loadDataWithBaseURL("file:///android_asset/", customHtml ,
"text/html", "utf-8", null);
webView.setWillNotCacheDrawing(false);
webView.destroyDrawingCache();
webView.setDrawingCacheEnabled(true);
webView.measure(MeasureSpec.makeMeasureSpec(480,
MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(800, MeasureSpec.EXACTLY));
webView.layout(0, 0, webView.getMeasuredWidth(),
webView.getMeasuredHeight());
webView.buildDrawingCache(true);
bmp = Bitmap.createBitmap(webView.getDrawingCache());
webView.destroyDrawingCache();
imageView.setImageBitmap(bmp);
}
}
activity_image_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ABABAB"
android:visibility="gone"
/>
</LinearLayout>
更新字符串 html