简体   繁体   中英

Android loading webview content full screen

When I give the following url to webview in android the content is getting displayed top left corner only. I want to make it full screen(content only). How can I make it?

http://staging.snagfilms.com/modules/html5player.jsp?filmId=ed9195a0-a748-11e0-a92a-0026bb61d036&w=500&html5=1

Xml:

   <LinearLayout
        android:id="@+id/layout_browser_new1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:layout_weight="1" >

        <com.verizon.viewdini.ui.custom.CustomFacedWebView
            android:id="@+id/web_wrap_browser"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

Code:

myWebView.getSettings().setPluginsEnabled(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setPluginState(PluginState.ON);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setScrollbarFadingEnabled(false);
myWebView.requestFocusFromTouch();

Use the code:

    Webview.getSettings().setBuiltInZoomControls(true);
    this.webview.getSettings().setLoadWithOverviewMode(false);
    this.webview.getSettings().setUseWideViewPort(false);

Use This this lines in xml

<WebView  
        android:id="@+id/webview_compontent"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1.0"   
    />

enable the following setting lines also.

 WebSettings webSettings = mWebView.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setLoadWithOverviewMode(true);
        mWebView.requestFocusFromTouch();

Hope this will help you.

add this to your HTML file:

<meta name="viewport" content="width=device-width"/>

after that, set this in your code:

WebView.getSettings().setLoadWithOverviewMode(true); WebView.getSettings().setUseWideViewPort(true);

Hope this will work.
In case setLoadWithOverviewMode doesn't work as you like, you can calculate the scale ratio between your website'sizee and the webview's size, then apply that scale with

WebView.setInitialScale(the_scale_ratio);

Remember to remove "viewport" tag in the HTML file in this case.

three steps to make it work.

  1. make layout full screen with no padding, no margin.

  2. make you web page surrounding no padding, no margin.

  3. make you web page surrounding no negative left, right, top, bottom floating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM