Назначьте вашему виду прокрутки идентификатор
<androidx.core.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lorem_ipsum"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Объявите свой вид прокрутки
NestedScrollView nestedScrollView;
Найдите свой вид прокрутки по идентификатору
nestedScrollView = view.findViewById(R.id.nested_scroll_view);
Установите прокрутку при включении смените слушателя на nestedScrollView
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY>scrollX){
Toast.makeText(getContext(), "Scrolling Down", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "Scrolling Up", Toast.LENGTH_SHORT).show();
}
}
});
и вуаля поместите свои действия в операторы if