我怎么可以加载图片的网址,以适合我的WebView在Android的? [英] How can i load image url to fit my webview in android?

查看:281
本文介绍了我怎么可以加载图片的网址,以适合我的WebView在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android application.Here我在web视图显示一个URL图像。但图像不适合我的WebView。有人建议使用视口的概念。但我不能够使用,完美。我在解释图纸的形式附在我的问题。我用

I am developing an android application.Here i am displaying a url image in webview. But the image is not fit to my webview. some one is suggested to use viewport concept. But i am not able to use that perfectly. I attached my issue in drawing form with explanation. I used

mWebView.getSettings().setUseWideViewPort (true);

但没有得到好的结果。 我需要显示拟合图像中的所有分辨率的设备,包括7寸,10寸平板电脑。 所以,请看看附加的图像,并建议我以正确的方式在我的WebView的地方,以适应URL图像。我想告诉我的形象一样第3图。

but not get the good result. I need to show the fitted image in all resolution devices including 7inch, 10 inch tablets. So please look at the attached image and suggest me the right way to fit url image in my webview place. I would like to show my image same as in 3rd diagram.

下面是我的code加载图像:

Here is my code for loading image:

webView = (WebView) findViewById(R.id.webimage);
        WebSettings webSettings = imageView.getSettings(); 
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setSupportZoom(true) ;
        webSettings.setBuiltInZoomControls(true);
        webView.setBackgroundColor(Color.TRANSPARENT);
        webView.getSettings().setUseWideViewPort (true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.setWebViewClient(new WebViewClient()
        {
        //some dialog implementation
        }
        webView.loadUrl(myurl);

推荐答案

您可以将宽度 IMG 100%的属性并没有设置height属性

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.

您可以refere我的问题<一href="http://stackoverflow.com/questions/13507281/how-to-show-certain-part-of-webpage-inside-webview-with-fit-screen-to-all-device">HERE

you can refere my Question HERE

虽然我已成功一些如何这个问题,一招用管理​​的高度和宽度设备的。并使用 wv.setInitialScale(185); ByDefault缩放将在左上角

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.

我已经把我下面的code。

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.

这篇关于我怎么可以加载图片的网址,以适合我的WebView在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆