I need to create a webview that I need to set a fixed size.
Say the webview should have a pixel width of 570, but the device only has a 320px width.
How do I render the webview size that is irrelevant to the parents size?
final WebView webView = new WebView(context);
webView.loadDataWithBaseURL("", html, "text/html", "utf-8", null);
webView.setDrawingCacheEnabled(true);
webView.setVisibility(View.INVISIBLE);
rootView.addView(webView);
webView.setWebViewClient(new CustomtWebClient(context));
In the CustomtWebClient
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
final WebView webView = view;
view.postDelayed(new Runnable() {
@Override
public void run() {
Bitmap bitmap = Bitmap.createBitmap(webView.getWidth(),
webView.getContentHeight() * (int) webView.getScale(), Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(bitmap);
webView.draw(c);
//additional stuff...
}
}, 100);
}
As you can see the webview should only be rendered and then turned into a bitmap.
But the way I do it now the webview is restricted to the parents size, which is based on the device.
I need an independent webview.