Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 visible in fit to screen mode in all the devices.

I'm resolving this Problem since last two three days.

What I want : I want to Show Top Left Corner of webpage to show inside Webview by Whatever the Stratergy May be with zoom or any other Option but it Should be fit to screen for all the device.

One More thing I can't change the Source Code of Webpage, because it is fixed. I have to manage by code itself.

enter image description here

What I have Tried : I have refer Stackoverflow links but no luck.

Here is my Code. :

            WebView wv;
        wv = (WebView) findViewById(R.id.webview_MyPoops);
        wv.getSettings().setJavaScriptEnabled(true);

        // wv.setInitialScale(185);

        // wv.setInitialScale(30);
        String URL = "MY_LINK";

        wv.loadUrl(URL);

        WebSettings webSettings = wv.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);

I'm getting complete webpage shown in devices.

It Works fine in My LG Device(Which has Resolution of 480*800) but in big device or tabs like Galaxy Tab2, I'm getting very small image of Top Left Corner and all other Area of screen are just background of WebPage.

Below is the screenshot of Galaxy Tab2 after Running the above code. enter image description here Please have you Any suggestion where I am lacking. Thanks in Advance.

like image 938
Bhavesh Patadiya Avatar asked Nov 22 '12 06:11

Bhavesh Patadiya


1 Answers

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();
        }
like image 133
kyogs Avatar answered Oct 11 '22 01:10

kyogs