How can i load image url to fit my webview in android?

余生颓废 提交于 2019-12-03 17:05:24
Bhavesh Patadiya

you can set width attribute of img to 100% and don't set height attribute

<body >
<img id="resizeImage" src="you_image.png" width="100%" alt="" />
</body>

Edited : Actually i also Having the Same Problem. However Still i am Waiting for the Correct Answer.

you can refere my Question HERE

though i have managed some how this Problem with a Trick by managing height and Width of Device. and Using wv.setInitialScale(185); ByDefault the Zoom will be in Top Left Corner.

i have put my code below.

WindowManager mWinMgr;
    public static int displayWidth = 0, displayHeight = 0;

    @Override
    protected void onCreate(Bundle icicle) {
        // TODO Auto-generated method stub
        super.onCreate(icicle);
        // this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        // this.setProgressBarVisibility(true);
        mWinMgr = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        displayWidth = mWinMgr.getDefaultDisplay().getWidth();
        displayHeight = mWinMgr.getDefaultDisplay().getHeight();

        setContentView(R.layout.view_my_poops);

        try {
            Map_Type = getIntent().getExtras().getString("MAP_TYPE");
        } catch (Exception e) {

        }
        Log.i(TAG, "MAP TYPE" + Map_Type);

    }

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        WebView wv;

        wv = (WebView) findViewById(R.id.webview_MyPoops);
        wv.getSettings().setJavaScriptEnabled(true);
        // this.setProgressBarVisibility(true);
        if (displayWidth >= 552 && displayHeight >= 976 || displayWidth >= 976
                && displayHeight >= 552) {
            wv.setInitialScale(185);
        } else {
            // wv.setInitialScale(150);
        }
        // wv.setInitialScale(30);


        URL = "YOUR_URL";


        Log.i(TAG, "Loading URL" + URL);

        final Activity activity = ViewMyPoop.this;

        wv.setWebChromeClient(new WebChromeClient() {

            public void onProgressChanged(WebView view, int progress) {
                // TODO Auto-generated method stub
                // Log.i(TAG, "Inside OnProgress Changed" + URL);
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);
                if (progress == 100)
                    activity.setTitle("My title");
            }
        });

        wv.loadUrl(URL);
        wv.setWebViewClient(new WebViewClient());
}

Hope it will Some How Help you.

Are u try below code for above problem:-

Display display = getWindowManager().getDefaultDisplay();
int width=display.getWidth();

String data="<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
data=data+"<body><center><img width=\""+width+"\" src=\""+url+"\" /></center></body></html>";
webView.loadData(data, "text/html", null);
kittu88

You can try this:

webView.setInitialScale(30);
WebSettings webSettings = webView.getSettings();
webSettings.setUseWideViewPort(true);

Refer: link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!