【发布时间】:2016-01-14 15:40:55
【问题描述】:
我有一个用于测试目的的网页 (https://storage.googleapis.com/htmltestingbucket/nested_scroll_helper.html),它只打印 html 在固定标题中捕获的滚动事件的计数器
当 Android WebView 是片段中唯一可滚动的元素时,一切正常,WebView 将滚动事件发送到页面
如果我想在 WebView 上方和下方添加原生元素,那么事情会变得更加复杂。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="SOMETHING ABOVE THE WEBVIEW" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="SOMETHING BELOW THE WEBVIEW" />
</LinearLayout>
</ScrollView>
我知道在 ScrollView 中包含 WebView 并不好,但我必须在 html 文档中提供混合内容和正确滚动事件的单一滚动体验。 我发现了很多关于此事的问题,但我能够创建一个完整的端到端解决方案
另外,我知道 lint 对此进行了官方检查:
嵌套滚动 --------------- 摘要:嵌套滚动小部件
优先级:7 / 10 严重性:警告类别:正确性
滚动小部件(例如 ScrollView)不应包含任何嵌套 滚动小部件,因为这有各种可用性问题
然而,我无法以原生方式实现 Web 视图内容,因此我需要另一种方法来实现这一点
【问题讨论】:
-
我在发布之前看到了它,请注意:“由于 Android KitKat 下文描述的解决方案都不起作用 - 您需要寻找不同的方法,例如 Manuel Peinado 的 FadingActionBar,它提供了一个滚动标题网络视图。” --> 我不想解决 webview 上方的原生元素的问题,这更容易
-
我不想解决仅在 web 视图上方的原生元素的问题,这要容易得多
-
是的,在我发布之前。您可以尝试使用我提供的 HTML。问题不在于缺少滚动.. 缺少 html 评分事件
标签: android webview android-scrollview