检测ScrollView是向上滚动还是向下滚动-Android [英] Detect if a ScrollView is scrolling up or down - Android

查看:542
本文介绍了检测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) 

这篇关于检测ScrollView是向上滚动还是向下滚动-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆