having trouble with zooming in android webview - android

I'm new to android. I'm using webview in scrollview to display my local html page (html has text only). I created two buttons for zoomin and zoomout using behind function zoomIn() & zoomOut() respectively. These functions work fine. The problenm is, when I zoom in, some of the text goes out from both top and bottom and it doesn't appear when I scroll.
How can I resolve this?

This question is pretty old, so it's probably answered already, but just in case...
When a WebView zooms, it clips the content to its own view rectangle. From the description of your setup, it sounds like you're scrolling the WebView itself within its parent scroll view. What you want to do is scroll the WebView's contents. You can do this by calling WebView.scrollTo or WebView.scrollBy (inherited from View), or conversely, from within the WebView's JavaScript by calling window.scrollTo.

Related

Android WebView pinchToZoom doesn't work correctly inside ScrollView

I have WebView inside a ScrollView and the WebView zoom functionality doesn't work correctly, because the ScrolView take focus and scrolls instead to zoom WebView.
I was thinking, that putting WebView inside ScrollView isn't the best idea, but unfortunately I don't know how else I can achieve wanted result.
I need to have few TextViews on the top of the screen and under them WebView which will show HTML content, but when I didn't use ScollView I can't see the whole content (scroll down of course).
So anybody has an idea how I can achieve scrolling without ScrollView or zooming WebView in ScrollView correctly?
Thank you!

WebViews inside ViewPager glitch: scrolls like sliding a stack of cards

My pager has one webview inside each fragment. The webviews themselves don't scroll, i.e. their content fit entirely in them.
The problem is the scrolling of the pager doesn't behave as expected. The webview content only follows the scrolling when going through the right edge of the screen (i.e. moving out/in to/from the right). When a webview is going through the left edge though it's content stays still (so that it looks like the next page is sliding over it, like cards).
I tried having other components (TextView, ImageView) along with the WebView on each page. They all slide normally while the WebView content keeps getting stuck on the left.
Is this a known problem? Is there a workaround?
Turns out the issue was CSS related.
I had "position:fixed" on all web content. After changing it to "absolute" the problem was solved.
In my point of view it's still an unexpected behavior, because "fixed" is supposed to position things relative to the browser window. What is expected is that, as the webview is scrolled left, the "browser window" moves past the device screen.

Scrollable and zoomable view with webviews

Let me start by saying - I know there are quite a lot of posts on this issue. I've been digging and testing it quite a bit, but couldn't come up with the proper solution to my specific requirements.
I need to have a master view with several webviews inside it, and more than one should be visible at a single moment. For this master view - I need to be able to scroll it (to reveal invisible webviews) and to zoom (in order to focus on a single webview).
I've tried TableLayout, but had problems with the zoom (and painting issues with the scrolling). I've tried scroll views, but also read it's not recommended.
Any ideas or recommendation regarding how to achieve this?
Thanks,
yakobom
A simple approach could be to have only one webview with the root html doc containing multiple iframes. Load each page in one of the iframes.
This way the scrolling/zooming could be handled by the webview itself.
Scrollable view can be achieved by adding a scroll view in .xml file and placing remaining text views, edit texts in that scroll view..
to scrolling webview:
mWebView2.getSettings().setJavaScriptEnabled(true);
mWebView2.getSettings().setLoadWithOverviewMode(true);
mWebView2.getSettings().setUseWideViewPort(true);
mWebView2.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView2.setScrollbarFadingEnabled(true);
to zooming webview:
webView.setInitialScale(50);
webPlanSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webPlanSettings.setUseWideViewPort(true);

Android ScrollView containing LinearLayout with WebView scroll behavior

I have a view hierarchy like this, a vertical ScrollView with a vertical LinearLayout containing two children:
ScrollView ->orientation:vertical, width:fill_parent, height: fill_parent
LinearLayout -> orientation:vertical, width:fill_parent, height: fill_parent
WebView -> width:fill_parent, height: fill_parent
GoogleAdView -> width:wrap_content, height:wrap_content
When scrolling to the bottom of the webview and clicking on any link there, though the page loads , the scrollbar stays at the bottom rather than moving to the top. I can programatically set the scroll using scroll.fullScroll(ScrollView.FOCUS_UP), but that causes the scrollbar to jump up visibly. I have tried hiding the scrollbar before the page loads with scrollView.setVerticalScrollBarEnabled(false) and then re-enabling it after the page loads before calling scroll.fullScroll(ScrollView.FOCUS_UP) but that still causes the scrollbar to "jump".
The WebView by itself handles scrolling much more nicely on page changes, looks like it hides the scrollbar and then makes it appear on top of the page after load. Is there a way to maintain this with ScrollView?
You cannot reliably put a WebView in a ScrollView.
Either embed your ad in your Web content, leave the banner fixed on the screen, or work out some other trigger to animate hiding the ad (e.g., goes away after 5 seconds).
I've solved this by adding the AD inside the webview. Unfortunately you won't be able to use any Ad network SDK's, but it's a much better user experience.
Use javascript injection to insert your ads after the webview loads.
The trick is to use loadDataWithBaseURL when loading content into the WebView. Simply doing a loadData doesn't cause the scroll offset to reset.

Android: WebView that is hidden in a ViewFlipper does not apply its WebSettings

I am working on an app that has multiple WebViews in a ViewFlipper. When I try to adjust the font size for all the webviews at the same time (by calling getSettings().setTextSize(TextSize)) only the current view in the flipper updates the font size. I also tried reloading (webView.reload()) the hidden views but it does not work at all.
The closest I have been able to get is by reloading the web views when they become the active view, but then there is a delay of few seconds until the font size updates (and I think page reloading is not a good answer to this anyway...).
Does anyone know how to update all views that are in a ViewFlipper? Thanks for your answers :)
All view inside viewflipper are initiated when you start or create Activity(depend on your code), so on flipping your web view is not updating. You should code inside OnFling() function for webview update, below link, you may looking for that..
Android ViewFlipper not flipping

Categories

Resources