Issue
I have tried to set the size for Webview that I define in program. But, when I run the app, the Webview is displayed fit to device screen. I don't want this to happen. How can I have my own size of Webview? Anyone can help?
WebView wv = new WebView(this);
wv.setPadding(50,0,0,50);
wv.setInitialScale(getScale());
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
I have created the screen size in this method:
private int getScale(){
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
Double val = new Double(width)/new Double(PIC_WIDTH);
val = val * 71d;
return val.intValue();
}
How to make the WebView to be displayed according to the size that I want?
Solution
Use the Below Code To set the height of webview.
In your layout file, for e.g.: webview.xml
<WebView
android:id="@+id/webview"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width=“100dp”
android:layout_height=“200dp”/>
then in your Activity,
WebView webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com");
Answered By - Vishal Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.