Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewPager automatically focuses WebView

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.

like image 264
amik Avatar asked Dec 07 '22 10:12

amik


1 Answers

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.

like image 106
amik Avatar answered Dec 25 '22 03:12

amik