NestedScrollView setOnScrollChangeListener未触发

时间:2017-10-07 12:57:12

标签: android nestedscrollview

我有一个简单的NestedScrollView。我想发现学校行动。但ScrollChangeListener以下未被调用。代码如下所示。任何人都可以指出这里有什么问题吗?我在Android监视器中看不到任何日志消息。

final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scrollview);

scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

        Log.e(TAG, "onScrollChange");

        if (scrollY > oldScrollY) {
            Log.i(TAG, "Scroll DOWN");
        }
        if (scrollY < oldScrollY) {
            Log.i(TAG, "Scroll UP");
        }

        if (scrollY == 0) {
            Log.i(TAG, "TOP SCROLL");
        }

        if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
            Log.i(TAG, "BOTTOM SCROLL");
        }
    }
});

下面是布局代码。

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme"
    tools:context="style.smash.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:showAsAction="always|collapseActionView"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:titleTextAppearance="@style/Theme.Styled.ActionBar.TitleTextStyle"
            app:titleTextColor="@color/title_text_color" />

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/main" />

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

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

0 个答案:

没有答案