webview 以头布局的形式添加到 RecyclerView 中,第一次进入页面,当页面中有 EditText 而且点击时,甚至是相似点赞更换图片、点击 WebView 任意区域,都会形成 WebView 自动滑动到最顶部;html
分析:个人 WebView 在 onPageFinish() 的时候进行从新测量了高度,因此点击事件等极可能是 WebView 获取焦点从新绘制了,故而想到不让WebView获取焦点,尝试过使用android
android:focusable="true" android:focusableInTouchMode="true
上述代码只能解决 WebView 区域之外的点击形成的WebView滑动至顶部问题,第一次进入 WebView 时点击依然会形成 WebView 滚动;最后想到了 code android:descendantFocusability="blocksDescendants",貌似完美解决web
<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 属性说明:布局
beforeDescendants:viewgroup会优先其子类控件而获取到焦点 afterDescendants:viewgroup只有当其子类控件不须要获取焦点时才获取焦点 blocksDescendants:viewgroup会覆盖子类控件而直接得到焦点
Android 5.0 + 部分手机上 WebView 加载 GIF图时 会形成 WebView 不停的闪烁code
解决方法查看个人另外一篇文章:WebView 5.0+闪烁以及白屏问题完美解决xml