白色屏幕的WebView成的ImageView [英] white screen webview into imageview

查看:127
本文介绍了白色屏幕的WebView成的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在它的图像来显示一些HTML,在ImageView的。所以,我创建了一个网页视图,我的位图转换本网页流量和我设置的ImageView与位图,但我有一个白色的屏幕。我查了位不为null。

My goal it is to display some html with an image in it, in an imageView. So I created a webview, I converted this webview in bitmap and I set this imageview with the bitmap, but I have a white screen. I checked the bitmap is not null.

你知道为什么我有一个白色的屏幕?也许有更好的方法来做到这一点..?

Do you know why I have a white screen?maybe there is a better way to do that..?

ImageViewActivity.java

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的管理食谱

HBase Administration Cookbook

     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

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

Update string html

推荐答案

我的答案测试您的应用程序,我给你在这里的刷新活动/ ImageView的?。 (显示HBase的管理书)无空白屏幕。
你有网络权限在manifest文件:

I am testing your application with the answer I gave you here Refresh activity/ImageView?. No blank screen(Hbase Administration book is displayed). Do you have the network permission in your manifest file:

<uses-permission android:name="android.permission.INTERNET"/>

和您再次自定义HTML code被搞砸了。你应该看看HTML字符串。结果
多数民众赞成在你的问题。结果

And again your custom Html code is messed up too. You should look at the html string.
Thats where your problem is.

这篇关于白色屏幕的WebView成的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆