I have an android app with ViewPager from the support library.
Inside fragment's view, I have some Views on top and a WebView with some HTML contents below them.
First page is loaded properly, but when switching between pages, every next page automatically scrolls down to the webview and focuses something in it (image, hyperlink) marking it with a default style (orange color on my phone). This is extremely weird, I don't know where it comes from and I want to get rid of this behavior. Each page should be on its top (scroll position 0) when opened.
It happens with a short latency after loading view (onCreateView), so setting scroll position to 0 in onCreateView did not help.
After sliding to another page, it should look like this:
good version http://imageshack.us/a/img254/4623/shotgood.png
But after approx. a second, it automatically scrolls down, focuses a link and looks like this:
bad version http://imageshack.us/a/img855/1848/shotbad.png
Anyone experienced such issue and knows solution?
Thanks in advance.
EDIT: I have noticed that this issue does not occur while I don't scroll vertically inside any fragment. After I scroll vertically and then slide to another page, it starts to happening on every next page.
After few days of searching, I've finally found solution described here:
Webview inside a View pager in android
point is adding
android:descendantFocusability="blocksDescendants".
to the outer-most linear layout.
Related
I have a RecyclerView using the LinearLayoutManager where each of the child cards contains a WebView. I load the data into the WebView using the loadData() method. Things work fine when I'm scrolling down the list, but when I scroll down far enough that the above views get recycled I get issues when I scroll back up.
When the RecyclerView reattaches the above child it reloads the data in the WebView, but it doesn't reload it until the WebView is on the screen. When the WebView loads its data, it pushes all the children below it down the screen. So instead of having the bottom of the WebView slowly appear on screen as I scroll up, the entire WebView jumps on to the screen at the top of the WebView. It's very jarring and not smooth at all.
Is there any way to tell the adapter or layout manager to load the WebViews ahead of time? I'd be happy with my app if the RecyclerView scrolled smoothly, but right now it's pretty much unusable any time I scroll back up.
Try Resizing WebView to Match the Content Size
Also might want to look at, Recycler View – pre cache views
In combo it works pretty good but I'm still trying to improve scrolling.
I know this is an old question, but stumbled upon it when researching another answer. Try to set the item view cache size higher.
RecyclerView.setItemViewCacheSize(int cacheSize)
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.
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);
I've stumbled upon another tricky error...
I'm using basic ViewPager, which consists of several pages, which are basically consisted of HTML, displayed by a WebView.
I use the method:
mWebView.loadDataWithBaseURL(null, html, "text/html", "utf-8", "about:blank")
for showing the contents. HTML is a String variable. Everything work fine, but I would expect all the views to be preloaded (I've set offscreenpage limit of the viewpager and even instantiate item is called right with the right data), but it isn't.
The webview is loaded, but displayed only after the click. It doesn't occur to me first, because I clicked everytime I wanted to show another page, but if you move to quickly, clicks get a bit delayed and no page is displayed. Only after I click again.
Or, if I drag one page and move slightly right, I can see that the another view is not loaded yet... it displays only after one second.
Has anybody encountered something similar?
Any help is appreciated.
I have the same problem and am looking for help, too. It seems that the entire ViewPager doesn't show up until it has focused after the click, but none of the requestFocus() nor requestChildFocus() did work.
One little different thing, the problem only happens to me when the ViewPager is initialized. When I moved to another page, the webview content displayed well.
I have found the solution for this: just simply use the ViewPager.setCurrentItem(position) to display the page that you want as default (normally the first page in my case).
You need to remove setPageTransformer in pager. I have same problem and I fixed it.
I've made an activity that looks a lot like the level select screen from angry birds: there is a grid of button, and you can scroll through pages of them by swiping right or left.
I built it by creating a layout of the buttons, and then adding those layout to a Gallery view.
The problem is the animation is jerky, even if you swipe extra slowly, the content jumps ahead. Even when you fling the gallery page, it skips and jumps along its way to its destination.
I am wondering how to fix this: Maybe the complex layout it making it non responsive during the inflate?
Do you know how to fix this, or of a good way to do a workaround using some other approach that will let me have 3 or more screens smoothly swiping from page to page?
You should be using ViewPager. This is available in android support packages. Gallery Widget will not be smooth if you add components into it which has a lot of touch actions.
http://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html