检测ScrollView是向上滚动还是向下滚动-Android

检测ScrollView是向上滚动还是向下滚动-Android

问题描述:

我有一个ScrollView和一个LinearLayoutTextView s.我想检测ScrollView何时向上或向下滚动以隐藏/显示ActionBar.

I have one ScrollView with one LinearLayout with TextViews. I want to detect when ScrollView is scrolling up or down to hide/show ActionBar.

您需要创建扩展ScrollView

public class ExampleScrollView extends ScrollView 

然后是覆盖onScrollChanged,它为您提供了旧的和新的滚动位置,您可以从那里检测到哪个方向

and then Override onScrollChanged that gives you the old and new scroll positions and from there you can detect which direction

protected void onScrollChanged(int l, int t, int oldl, int oldt)