最近遇到一个奇葩问题,RecyclerView 嵌套的 WebView ,点击 WebView 容器后,界面自动滑到顶部,该滑动不是web界面滑动,RecyclerView滑动
刚开始想到的就是焦点问题,滑动冲突,RecyclerView 设置滑动item操作,获取通过接口调用等方式,分别进行调试之后都没发现问题,
其实能发生这种现象的大概率也就是以上问题,经调试,点击其他部分没有问题,也没有后端或者h5端调用相应的方法,只点击web容器才会发生以上现象,所以更加确定是焦点问题,刚开始只在RecyclerView上设置了焦点,无效果,所以饶了老长时间圈子也没有解决,经大佬调试解决结果如下:
通过 android:descendantFocusability=“blocksDescendants” 去获取焦点即可
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:gravity="center|top">
<RecyclerView
android:id="@+id/ShiChangRecyclerView"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
还遇到一个问题: WebView刷新如果会导致原生界面异常可以 尝试一下用 .GoBackOnLoad();方法让网页自己刷新,而不是用 Reload(); 方法同时去刷新Web容器