How to show Certain Part of WebPage inside Webview With Fit Screen to All Devices

前端 未结 5 2181
终归单人心
终归单人心 2021-02-19 23:13

I Want to Show WebPage Inside WebView. Up to this it is fine.

But I have WebPage (As Given Below) and I want Certain Part of it. I mean just Top Left Corner should be vi

相关标签:
5条回答
  • 2021-02-19 23:46

    On the HTML page you can have something like target-densitydpi=240; depending on device type just set this parameter from your Java code, the page will automatically fit to target density.

    0 讨论(0)
  • 2021-02-19 23:55

    You could try using HtmlCleaner (examples of how to use it here) to get the html from the webpage, then extract the part you want to display and load it into the WebView using: WebView.loadData();.

    I used this method in one of my apps to reformat a page so that it would be easier to use on a mobile device.

    0 讨论(0)
  • 2021-02-19 23:58

    try with this code hop this work for u.

    webview.setInitialScale(getScale()); 
    
    
    
    private int getScale(){
                Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
                int width = display.getWidth(); 
                Double val = new Double(width)/new Double(200);
                Log.e("hh", "** "+val);
                val = val * 100d;
                Log.e("hh", "** "+val);
                return val.intValue();
            }
    
    0 讨论(0)
  • 2021-02-19 23:59

    I believe the fix should be done only at the web page level and ideally WebView cannot do any tricks here. WebView is simply a browser(to be specific chromium browser) which should just do rendering as instructed by the web page.

    In order to actually fix your issue, you should try modifying the CSS of the web page.

    0 讨论(0)
  • 2021-02-20 00:01
    WebView x;
    
    x.setInitialScale(1);
    

    This is the furtheset zoom possible. But for some sites it just looks pure UGLY.

    This was the second version I found

    test1.getSettings().setDefaultZoom(ZoomDensity.FAR);
    

    Thats a nice all rounder than seems to just zoom out far enough for a lot but still not what I was looking for.

    And now here is the final solution I have.

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

    Basically what these do is answered in another question like this.

    setLoadWithOverviewMode(true) 
    

    Loads the WebView completely zoomed out

    setUseWideViewPort(true)
    
    0 讨论(0)
提交回复
热议问题