Per*_*rry 9 html css android scroll webview
我的应用程序中有一个WebView,其中包含HTML内容,HTML内容的大小大于WebView的大小.当用户将他/她的手指拖到其上时,由于哪些内容在其内部滚动.我想停止内容滚动发生内容.
这是迄今为止我已经尝试过的内容:
WebView view = new WebView(context); //context is of Activity
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
view.setScrollContainer(false);
Run Code Online (Sandbox Code Playgroud)
在CSS中:
overflow : hidden !important;
Run Code Online (Sandbox Code Playgroud)
请建议除了禁用手指拖动(黑客)以进行webview 之外的解决方案,因为这会影响我的其他功能,如下所示:
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_MOVE)
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
将一个容器添加到您的 web 视图中,该容器包含所有内容并位于body元素下方,如下所示:
<body id="myBody">
<div class="container">
<!-- All your content goes in this new div.container -->
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
然后,将此 CSS 添加到您的页面:
body {
height: 100%;
width: 100%;
pointer-events: none;
}
div.container {
overflow: hidden!important;
height: 100%;
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
问题在于,尽管有溢出规则,WebView 似乎还是忽略了滚动body,并且由于 abody会扩展以满足其内容,因此它总是认为还有更多内容可以滚动。它所做的是将主体重置为 WebView 的大小,然后使用容器来防止主体扩展到 WebView 之外并包含更多内容。
希望有帮助。