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.
Related
My UI consists of a ScrollView that takes the top 50% of the screen and under that two buttons that are attached to the bottom of the screen; YES and NO. The content of Scrollview is text that for most phones does not fill up the visual area of the ScrollView. However sometimes the text can be longer, such that it fills beyond the visual area of the ScrollView, hence the reason I added the ScrollView.
My problem is this; even when the ScrollView has very little text and does not need to scroll to show all of its content it still scrolls. The user can scroll the content up a slight amount. I'd like the View to instead not allow any scrolling if all the content is visible.
Is there an easy way to achieve this? Or do I have to implement that myself?
You cannot disable the scrolling of a ScrollView. You would need to extend to ScrollView and override the onTouchEvent method to return false when some condition is matched. To get help with extending, please read the answers to Disable ScrollView Programmatically?
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)
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!
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.
I have a webview, i am loading it with data, its in scrollview, i want to block scrolling when it scroll down to end of displayed content, i have tried javascript approach with adding div at end of content, getting it position and checking is scroll beyond it but it didtnt worked out, values returned by my script are wrong, getcontentheight is wrong too, and i am really pissed off, how is that possible that webview can scroll beyond it contents??? is this default behavoiur? i just want to display normal html, and i dont want to scroll beyond it
Just use only WebView without scrollView and use layout_height wrap_content.