一个web视图内配合网页内容(安卓)视图、网页、内容、web

2023-09-05 00:09:23 作者:荷露虽圆不是珠

简单的问题。

我想舒展的WebView的内容,使整个网页中是可见的。即没有滚动。我已经通过了文档看了,但找不到任何方法旁白从缩放控制和setinitialscale。

I'm trying to stretch the contents of a webview so that the entire webpage within is visible. i.e no scrolling. I've looked through the docs but cant find any method asides from zoom controls and setinitialscale.

在这种情况下,与setinitialscale的问题是,它的工作方式不同对于不同的位点。

The problem with setinitialscale in this case is that it works differently for different sites.

例: 1:维基百科将正常加载与变焦远远不够了。 2:但是谷歌将只显示页面的中央

Example: 1:wikipedia will load as expected with the zoom far enough out. 2:Google however will only show the center of the page.

继承人的code段我有

Heres the code snippet I have

    test1 = (WebView) findViewById(R.id.webview_test_1);
    test2 = (WebView) findViewById(R.id.webview_test_2);
    test3 = (WebView) findViewById(R.id.webview_test_3);

    test1.getSettings().setJavaScriptEnabled(true);
    test2.getSettings().setJavaScriptEnabled(true);
    test3.getSettings().setJavaScriptEnabled(true);

    test1.setInitialScale(12);
    test2.setInitialScale(12);
    test3.setInitialScale(12);

    test1.loadUrl("http://developer.android.com/resources/tutorials/views/hello-tablelayout.html");
    test2.loadUrl("http://www.wikipedia.org/");
    test3.loadUrl("http://www.google.com");

test1.getSettings().setDefaultZoom(ZoomDensity.FAR);

这似乎是一个替代方案是什么,我试图做的,但我不能让它放大远远不够。

This seems to be an alternative to what I'm trying to do but I cant get it to zoom far enough.

推荐答案

所以,人们可以用这个作为未来的教程。

So People can use this as a tutorial in the future.

有一堆方法来处理在Android和配件页面缩放。它可以在次pretty的气质,有些方法的工作比别人做得更好。

There are a bunch of ways to handle zooms in android and fitting pages. It can be pretty temperamental at times and some methods work better than others.

对于大多数人来说,只要使用

For most people, Just use

的WebView X;

WebView x;

x.setInitialScale(1);

这是furtheset放大的可能。但是,对于一些网站,它只是看起来纯粹的丑陋。

This is the furtheset zoom possible. But for some sites it just looks pure UGLY.

这是我发现的第二个版本

This was the second version I found

test1.getSettings().setDefaultZoom(ZoomDensity.FAR);

这就是一个很好的多面手比似乎只是缩小远远不够了很多,但仍然不是我所期待的。

Thats a nice all rounder than seems to just zoom out far enough for a lot but still not what I was looking for.

而现在继承人的最终解决方案,我有。

And now heres the final solution I have.

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

基本上,这些做的是回答这样一个问题。

Basically what these do is answered in another question like this.

 setLoadWithOverviewMode(true) 

加载的WebView完全缩小

Loads the WebView completely zoomed out

setUseWideViewPort(true)

使所述web视图有一个正常的视口(如正常的桌面浏览器),而当假web视图将具有视约束到它自己的尺寸(因此,如果web视图是50像素* 50像素的视口将是相同的尺寸)

Makes the Webview have a normal viewport (such as a normal desktop browser), while when false the webview will have a viewport constrained to it's own dimensions (so if the webview is 50px*50px the viewport will be the same size)