I'm trying to act on Scroll Events inside(!) a (Nested)Scrollview.
I have an Item inside a Scrollview that i want to "peek" (translate to visible screen area) for a few sec if it's not initially visible in the scrollview/screen. But as soon as the container is scrolled, i want to hide it (translate back to origin).
Therefore i'm trying to use a CoordinatorLayout Behavior to not tightly couple the scrollView and my (custom) View.
Following the article, I tried to write a custom behavior, but figured out, that I cannot apply this Behavior on my view, as it's not a child of the CoordinatorLayout. If i have to set it on a direct child, how can i then act on the great-grand child?
How could this be achieved?
Layout looks sth like that:
<CoordinatorLayout>
<NestedScrollView>
<LinearLayout>
...
<MyView/>
<LinearLayout/>
</NestedScrollView>
</CoordinatorLayout>
The behaviour is pretty straight forward:
public class MyBehaviour extends CoordinatorLayout.Behavior{ ... @Override public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) { return true; } @Override public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); // act on MyView } }