检测ScrollView是向上滚动还是向下滚动-Android
问题描述:
我有一个ScrollView
和一个LinearLayout
和TextView
s.我想检测ScrollView
何时向上或向下滚动以隐藏/显示ActionBar
.
I have one ScrollView
with one LinearLayout
with TextView
s. 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)