当前位置: 代码迷 >> Web前端 >> WebView 加载url时顺应屏幕
  详细解决方案

WebView 加载url时顺应屏幕

热度:289   发布时间:2012-08-28 12:37:01.0
WebView 加载url时适应屏幕
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
       
        setContentView(R.layout.main);

        WebView mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setUseWideViewPort(true);
        //放大缩小
        mWebView.getSettings().setBuiltInZoomControls(true);
        //适应全屏按比例缩放   可通过修改 39这个参数来设置适应屏幕的尺寸
        mWebView.setInitialScale(39);

        mWebView.loadUrl("http://www.wwgupiao.com/game/");
       
        mWebView.setWebViewClient(new WanWeiWebViewClient());
    }
    private class WanWeiWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }