在Android 2.3或更低版本中,NestedScrollView中的WebView滚动问题

10

我在我的安卓应用程序中添加了ToolbarTablayoutViewpager。在TabLayout中有三个Tabs,每个都显示一个WebView

我将WebView放在NestedScrollView中,以便在用户向下/向上滚动WebView时隐藏/显示Toolbar。在Android 3.0或更高版本中,Toolbar会隐藏。

但不幸的是,在Android 2.3或更低版本中,WebView一开始无法滚动。我必须滑动到另一个标签页,然后再返回第一个TabWebView才开始滚动。

我想要什么?

我希望在Android 2.3或更低版本中,WebView能够毫无问题地滚动。

我的WebView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="1dp">

     <WebView
         android:id="@+id/webviewtool"
         android:layout_width="match_parent"
         android:layout_height="fill_parent"
         android:numColumns="1"
         android:scrollbars="none"
         android:focusableInTouchMode="false"
         android:focusable="false"
         android:background="#FFFFFF" />

        </LinearLayout>
</android.support.v4.widget.NestedScrollView>
1个回答

3
尝试使用这个库:https://github.com/ksoichiro/Android-ObservableScrollView,它可以在API 9+上正常工作。但请注意,2.3版本存在许多与视觉、动画等相关的问题。
你也可以下载并查看代码示例:"ActionBarControlWebViewActivity WebView & Action Bar",这正是你要找的。链接:ActionBar & WebView 使用起来就像这样简单:
ObservableWebView webView = (ObservableWebView) findViewById(R.id.web);
webView.setScrollViewCallbacks(this);
webView.loadUrl("file:///android_asset/lipsum.html");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接