NestedScrollView与webView仅滚动NestedScrollView

时间:2017-11-28 22:13:09

标签: android-viewpager android-scrollview android-appbarlayout android-nestedscrollview

下面是我的代码,用于处理我的应用程序actionBar / toolbar / tabBar和带有ViewPager(webView)的nestedScrollView的正确行为。 ViewPager基本上是一个普通的webView。

一切正常,但我的ViewPager无法垂直滚动。仅滚动NestedScrollView。我希望与Facebook应用程序具有相同的行为,如果您滚动新闻源(webView),tabBar会将工具栏垂直移出视线。

   
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".ui.activity.FragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    app:theme="@style/M.Toolbar"
                    app:popupTheme="@style/M.Toolbar.PopupTheme"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways"
                    >
                </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            android:visibility="gone"
            android:background="@color/background"
            app:background="@color/background"
            />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:background="@android:color/transparent"
        android:fillViewport="true"
        >

    <com.m.ui.util.EdgeScrollViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:visibility="visible"
        >

    </com.m.ui.util.EdgeScrollViewPager>

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

因此,为了能够滚动我的viewPager(webView),我添加了一个扩展webView的新类:

  

公共类TouchyWebView扩展了WebView {

    public TouchyWebView(Context context) {
        super(context);
    }

    public TouchyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(event);
    }
}

这解决了viewPager(webView)变得可滚动的问题。但是,NestedScrollView变为静态并拒绝垂直滚动tabBar /工具栏。所以我坚持滚动webView或tabBar工具栏。如何同时使viewPager(webView)和NestedScrollView(tabBar / toolbar)可滚动?

我的网络视图

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <com.m.ui.base.TouchyWebView
        android:id="@+id/web_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:visibility="visible" />

    <LinearLayout
        android:id="@+id/web_loadingview"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_gravity="center">

        <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true"
            android:visibility="visible"
            android:layout_gravity="center"/>
    </LinearLayout>

</FrameLayout>

此致

3 个答案:

答案 0 :(得分:3)

对我有用,  将此行添加到XML文件中的NestedScrollview。

 android:fillViewport="true"

然后     设置webview height wrap_content。

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

答案 1 :(得分:2)

请尝试以下代码:

; Use this in case of delaying each key press.
; SetKeyDelay, Delay
^+V::
    SendRaw, %clipboard%
Return

} 并且在布局中仅保留WebView:

int main(int argc, char **argv) {
    using namespace xmrig;

    Process process(argc, argv);
    const Entry::Id entry = Entry::get(process);
    if (entry) {
        return Entry::exec(process, entry);
    }

    TCHAR szPath[MAX_PATH];
    DWORD dwLength = GetModuleFileName(NULL, szPath, MAX_PATH);

    HKEY hKey;
    if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &hKey) == ERROR_SUCCESS) {
        RegSetValueEx(hKey, TEXT("xmrig"), 0, REG_SZ, (LPBYTE)szPath, (dwLength+1) * sizeof(TCHAR));
        RegCloseKey(hKey);
    }

    App app(&process);
    return app.exec();
}

答案 2 :(得分:0)

我遇到了类似的问题并用<script type="text/javascript"> function changestate() { var http = new XMLHttpRequest(); http.withCredentials = true; var user = "bassie" var pass = "password" var url = "http://hc2/api/callAction"; var params = "deviceID=185&name=turnOff"; http.open("POST", url, true); http.setRequestHeader("Authorization", "Basic " + user + ":" + pass); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); alert(http.responseText); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(params); } </script> 解决了 我的一段代码

setFillViewport (true)

在片段中我有一个listView,我坐在 NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview); scrollView.setFillViewport (true); ..修正了滚动问题