I'm in need of two things:
I need to display a webview that shows the entire webpage (horizontally), and automatically shrinks it to whatever width necessary to display the entire page edge to edge. I'm curious if this
a) can be done at all
b) if so, is this something I can control with JUST the WebView or
c) if I need to modify the HTML of the page to squeeze into whatever the container happens to be.
I have a situation where I need to display Facebook (and Twitter and Pinterest) in WebViews that scale to the size of the device and I want to make sure the WebViews show the entire page rather than creating Horizontal scrollbars.
Then, I'm curious if there's some way I can auto scroll down to a specific coordinate from the WebView so that I can scroll down beneath the massive banners that Twitter and Facebook have at the top and display the users' content without them having to scroll down manually.
Can this be done?
In order to have the WebView shrink the page to the width of the screen, use the following settings in your code.
WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
you can use:
int x = 0, y = THE_NUMBER_YOU_WANT;
view.scrollTo(x,y);
to scroll to any position on the webpage, determining how far you have to scroll down will be challenging though.
Related
I'm using WebView to show some html content with different width. Initial scale is set up to show all page content. without horizontal scroll. This code is used:
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
Now I want to forbid zoom out but keep zoom in enabled. Can anyone help to find the way?
UPD:
Some additional explanations.
I want to limit minimum scale for webView. For example, If scale=0.67 make page to fit the width of WebView I want to forbid user set scale less then 0.67, but keep the possibility to set scale greater than 0.67. Main problem here is that displaying content has different width and therefore minimal scale is different for different pages.
I can tell you that what you are trying to achieve is a Bad UX. Zoom in and Zoom out are related to each other. If the user zoomed in by mistake, and found out that you are preventing him from zooming out. Expect disappointment and maybe 1 star on the market.
Even the WebView does not allow you to enable one and disable the other.
But if you really want to do that, then you need to implement the gesture by yourself and calculate the difference between the figures. If the difference is getting bigger (ZoomIn) otherwise (ZoomOut)
This link will help you implement the Zoom Gesture
I use a android.webkit.WebView to display some HTML formatted info to the user. Whenever I "page" in my application, I reuse all the graphical elements on screen and just fill them with different content. A WebView will by default increase its size to fit the contents, but won't decrease if the content shrinks.
To fix this, I call webView.clearView() to clear the view and then webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null)to reload it with data. It works, but it creates a very strange behavior where the view starts to flicker persistently. The flickering area seems to be the same size as what would have been left empty after filling it with smaller content.
I can't describe this better with words, so I created a short video to illustrate the problem:
http://www.youtube.com/watch?v=yL7tQpRSFe0
The WebView is the yellow box on the lower part of the screen.
Am I doing something wrong, or is it a bug?
If this is an Android bug, is there a better way to resize the view as to circumvent this problem?
Is it possible to scroll out of the page bounds in a webview?
Example: Webview page/content width: 15px, screen size: 10px. Can I scroll to X position 8px?
Technically I can, and it worked fine on my test device. However, testing on other devices I notice that it will stop rendering when I move out of the bound. The left part of the page will be 'blurry' or not visible at all, till I scroll back left and there is no more "empty space" in the webview, than it will update.
Is there a solution for this?
A possible solution would be making the content larger on the fly, with white space. But I cannot add padding to the webview, unless I put it in the html BEFORE I render it. But before I render it I won't know the width. After I render it there is no way to change the padding/add some empty space to the content, without loading it completely again. Right?
I solved this by added 1-2 page-breaks at the end of the html, it will render fine now and I customly prefent the view from scrolling to the end of the page, so that the white is not shown to the user.
So I have a local HTML file with CSS and I need to display this file in the form of a book (scroll left/right to view previous/next content, not up and down). I've thought of a really complicated ways to achieve this:
A Gallery of WebViews
Disable scrolling in the WebView
On swipe, scroll the WebView down the height of the WebView
There's a couple of problems with this approach:
I'd have to have the HTML content loaded for each WebView (extremely inefficient)
There exists the possibility that at the bottom of the page, there would be some content partially hidden
I'm looking for some suggestions on how to approach this problem, as the only thing I've came up with sounds dreadful. Thanks!
You could use two frames or iframes side by side and load odd page numbers in the left frame and even page numbers in the right frame. Put some fancy control buttons on each page, or a javascript scrollbar under the frames, and a div with a page-flipping animation that you can turn on or off when pages are loaded into the frames. I think it's totally doable, and could actually be pretty slick.
I can't help you totally, but here is a good example for page curl animation with custom view.
https://github.com/harism/android_page_curl/tree/master/src/fi
hi how to set scroll length to web view in android?
i wanted to scroll web screen for fixed length. I'm displaying a web page in web view and i adjusted web content using div tag to scroll horizontally. till here no problem and i want to add feature to webview that once user tap the screen horizontally it should move up to fixed length to the right.
Do you know how to do it with JavaScript? When handle a tap on Android side, and then use
WebView.loadUrl("javascript:....")
to adjust scroll offset of browser window.