Android的web视图最初的缩小 [英] Android Webview initial zoom out

查看:132
本文介绍了Android的web视图最初的缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的WebView在我的Andr​​oid应用程序,在当应用程序启动后会被放大了不少网站的那一刻,我希望它被缩小以适合屏幕的宽度。我现在有这在我的活动:

  super.onCreate(savedInstanceState);
    的setContentView(R.layout.shop);
    的WebView的WebView;
    的WebView =(web视图)findViewById(R.id.webview);
    webview.setWebViewClient(新WebViewClient());
    webview.getSettings()setJavaScriptEnabled(真)。
    webview.loadUrl(http://www.example.com);
 

解决方案

  webview.getSettings()setLoadWithOverviewMode(真)。
 

这将导致web视图要最初缩小。

  webview.getSettings()setUseWideViewPort(真)。
 

web视图将有一个正常的视区(如桌面浏览器),当假的WebView将有一个视受限于它自己的尺寸。

修改:随着Android的奇巧推出Chrome浏览视图,这code可能无法正常工作

I'm using a webview in my android app, at the moment when the app is started the website is zoomed in quite a lot, i want it to be zoomed out to fit the width of the screen. I currently have this in my activity:

super.onCreate(savedInstanceState);
    setContentView(R.layout.shop);
    WebView webview;
    webview = (WebView) findViewById(R.id.webview);
    webview.setWebViewClient(new WebViewClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.example.com");

解决方案

webview.getSettings().setLoadWithOverviewMode(true);    

This will cause the webview to be zoomed out initially.

webview.getSettings().setUseWideViewPort(true);

The Webview will have a normal viewport (like desktop browser), when false the webview will have a viewport constrained to it's own dimensions.

EDIT: With the introduction of "Chrome web view" in Android KitKat, this code might not work.

这篇关于Android的web视图最初的缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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