I have a fixed content in my text view inside a scroll view. When the user scrolls to a certain position, I would like to start an activity or trigger a Toast.<
NestedScrollView is just like android.widget.ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.
1st - Use NestedScrollView binding instead ScrollView
2nd - Set Scroll listener, like this, to detect axis Y moving for a headerView by example
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
Log.d(TAG, "onScrollChangeForY - scrollY: " + scrollY + " oldScrollY: " + oldScrollY);
int MOVE = -1, SCROLL_UP = 0, SCROLL_DOWN = 1;
float initialPositionY = headerView.getY();
MOVE = scrollY > oldScrollY ? SCROLL_UP : SCROLL_DOWN;
if (MOVE == SCROLL_UP) {
int incrementY = scrollY - oldScrollY;
headerView.setY(initialPositionY - incrementY);
} else {
int incrementY = oldScrollY - scrollY;
headerView.setY(initialPositionY + incrementY);
}
}
});