Scenario One
WebView in the form of head layout added to the Recyclerview, the first time to enter the page, when the page has EditText and click, even like to change pictures, click WebView Any area, will cause webview automatically slide to the top;
Analysis: My WebView in Onpagefinish () the time to re-measure the height, so the click event is likely to be WebView to get the focus to redraw, so think of not let WebView get focus, tried to use
android:focusable="true" android:focusableInTouchMode="true
The above code can only solve the WebView sliding to the top problem caused by clicking outside the WebView area, and clicking on the first entry to the WebView will still cause WebView scrolling; Finally, I thought of code android:descendantfocusability= "Blocksdescendants", seemingly perfect solution
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:descendantFocusability="blocksDescendants"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
Descendantfocusability Property Description:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点 afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点 blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
Scenario Two
WebView on Android 5.0 + some phones will cause WebView to flicker when loading GIF images
Workaround View My other article: WebView 5.0+ Flicker and white screen problem perfect solution
Android WebView the road to the pit of civilization