WebView不滚动
我在屏幕上的NestedScrollview中有一个WebView。另外,我在屏幕下方有recyclerview,当recyclerview关闭WebView时,我向上滚动以再次查看WebView,那时WebView的内容停止了滚动。我如何解决?
<androidx.core.widget.NestedScrollView
android:id="@+id/webScrollContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:visibility="@{playerType == PlayerViewType.WEB ? View.VISIBLE : View.GONE}"
tools:visibility="gone">
<WebView
android:id="@+id/previewWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:isScrollContainer="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</androidx.core.widget.NestedScrollView>
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
private fun initWebView() {
web.let {
with(it.settings) {
javaScriptEnabled = true
userAgentString =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.117 Safari/537.36"
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
mediaPlaybackRequiresUserGesture = true
allowFileAccess = true
cacheMode = WebSettings.LOAD_DEFAULT
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.setLayerType(View.LAYER_TYPE_HARDWARE, null)
}
it.webChromeClient = WebChromeProgressClient()
it.webViewClient = WebClient()
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的布局中:
In your Layout:
问题是由
WebView
nestedscrollview
。
recyclerveive
a href =“ https://developer.android.com/reference/android/webkit/webview” rel =“ nofollow noreferrer”>webview
,但在最终中“ https://developer.android.com/reference/android/webkit/webview” rel =“ nofollow noreferrer”>webview
不再滚动。创建一个
/a>要实现a
custom
nestedwebview class
classnestedscrollingscrollingchild interface
。它应该覆盖
ontouchevent()方法
。修复此设置
android:nestedScrollingEnabled =“ true”
for NestedScrollview 。这将允许webview
href =“ https://developer.android.com/reference/androidx/core/widget/nestedscrollview” rel =“ nofollow noreferrer”>nestedscrollview
。我还要做的是禁用硬件的加速度。尝试调用
it.set.set.setlayertype(view.layer_type_software,nul)
,而不是
it.setlayerType(view。 layer_type_hardware,nul)
。设置
webview
“ https://developer.android.com/reference/kotlin/androidx/core/widget/nestedscrollview” rel =“ nofollow noreferrer”>nastedScrollingEnabled
>。它将禁用滚动。将其添加到您的initwebview()fun
:
之前对其进行测试,因为它可能会影响您的性能。
最后一个解决方案是使用自定义WebView 实现 /代码> 。
.kt文件
.xml布局
初始化并使用自定义
nestedwebview
用regwebview
。The issue is caused by
WebView
that is inside of aNestedScrollView
.The
RecyclerView
covers theWebView
but in the final theWebView
isn't scrolling anymore.Create a
custom
NestedWebView Class
to implement aNestedScrollingChild Interface
. It shouldoverride
onTouchEvent() Method
.Fix this setting
android:nestedScrollingEnabled="true"
forNestedScrollView
. This will allowWebView
to scroll withinNestedScrollView
.What I would additionally do is to disable the acceleration of hardware. Try to call
it.setLayerType(View.LAYER_TYPE_SOFTWARE, nul)
, instead ofit.setLayerType(View.LAYER_TYPE_HARDWARE, nul)
.Set the
WebView
'sNastedScrollingEnabled
propertyfalse
. It will disable scrolling. Add this in yourinitWebView() fun
:Test it before because it may affect your performance.
The last solution is the usage of
custom WebView
to implementNestedScrollingChild interface
..kt file
.XML layout
Initialize and use the custom
NestedWebView
instance with regWebView
.