android webview 不同手机屏幕,Android webview适合所有内容到屏幕

嗨,我有一个webview,我希望它适合屏幕,这样用户不必水平或垂直滚动

我以前搜索过,很多人建议如下,但它只限制宽度,用户仍然需要垂直滚动:engine = (WebView) (findViewById(R.id.webView1)); engine.loadUrl(www.example.com); engine.getSettings().setLoadWithOverviewMode(true); engine.getSettings().setUseWideViewPort(true);

我尝试了另一种方法,使用缩放方法,但它不会工作…..我得到窗口宽度(1024像素),网页内容宽度也是1024像素! 因此缩放不起作用….有没有任何方法来获得正确的比例?

或….还有其他方式吗?….谢谢!!

// get the window width and height Point outSize = new Point(); getWindowManager().getDefaultDisplay().getSize(outSize); width = outSize.x; height = outSize.y; Log.i("Menuboard", "width: " + Integer.toString(width) + ", height: " + Integer.toString(height)); WebViewClient client = new WebViewClient() { public void onPageFinished(WebView view, String url) { int x = engine.getWidth(); int y = engine.getHeight(); Log.i("Menuboard", "web width: " + Integer.toString(x) + ", height: " + Integer.toString(y)); int scale1 = width * 100/x; int scale2 = height * 100/y; Log.i("Menuboard", "Scale1: " + Integer.toString(scale1) + ", Scale2: " + Integer.toString(scale2)); if (scale1 scale2) { engine.setInitialScale(scale2); Log.i("Menuboard", "scale2: " + Integer.toString(scale2)); } } }; engine = (WebView) (findViewById(R.id.webView1)); engine.loadUrl(string); engine.getSettings().setBuiltInZoomControls(true); engine.setPadding(0, 0, 0, 0); engine.setWebViewClient(client);

只是一些说明:

要缩放webview:

engine = (WebView) (findViewById(R.id.webView1)); engine.loadUrl(www.example.com); engine.getSettings().setBuiltInZoomControls(true); engine.setPadding(0, 0, 0, 0); engine.setInitialScale(50); // 0 - 100 where 100 is full scale

要获得窗口宽度和高度:

Point outSize = new Point(); getWindowManager().getDefaultDisplay().getSize(outSize); width = outSize.x; height = outSize.y;

使用以下方法。

webview.getSettings().setUseWideViewPort(true); webview.getSettings().setLoadWithOverviewMode(true);

要使webview扩展到整个屏幕,请在活动布局xml中添加webview,并确保将layout_width和layout_height设置为fill_parent 。 这是一个简单的例子:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值