I have two toolbars( one set as "enterAlways" and the other is "scroll") and a recyclerview in a coordinatelayout, what I wanted to achieve is to capture scroll event when the recyclerview has not been scrolled, which means when the toolbar which has been set as "enterAlways" is still scrolling.
But when I tried coordinateLayout.setOnScrollChangeListener() , its not working at all.
my layout is like this:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_wrapper">
<EndlessRecyclerView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff0000"
>
<include app:layout_behavior="com.viki.android.adapter.AbsListener"
android:id="@+id/header_upper" layout="@layout/inlcude_channelheader_upper" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll"/>
<include android:id="@+id/header_lower" layout="@layout/include_channelheader_lower" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="enterAlways"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
How exactly can I capture the scroll event and also the value for dx and dy like what onScrollListener for listview or recyclerview does.
CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.
The solution is simple, we just need to set the app:scrimAnimationDuration=”0" in our collapsing toolbar layout like the below code snippet. Now just run the code and see the results, you will see then there will be no fading animation anymore.
AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures. Children should provide their desired scrolling behavior through AppBarLayout.
AppBarLayout
provides a listener you can implement to listen for when the AppBarLayout
's scrolling siblings move up/down. What you want to do is implement that listener and register it with your AppBarLayout
as follows:
mAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
Log.d("tag_scroll", "recycler_view current offset: "+verticalOffset);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With