Android下 scrollview的滚动停止事件的监听方法
使用递归调用的方法,每隔5毫秒检查一下是否已经停止,如果已经停止,就拿到事件啦!
不扯蛋,直接上代码。
scrollContent就是我的scrollview。
[代码]java代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
ScrollView scrollContent ; scrollContent.setOnTouchListener( new OnTouchListener() { private int lastY = 0; private int touchEventId = -9983761; Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super .handleMessage(msg); View scroller = (View)msg.obj; if (msg.what==touchEventId) { if (lastY ==scroller.getScrollY()) { handleStop(scroller); } else { handler.sendMessageDelayed(handler.obtainMessage(touchEventId,scroller), 5); lastY = scroller.getScrollY(); } } } }; @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { handler.sendMessageDelayed(handler.obtainMessage(touchEventId,v), 5); } return false ; } //这里写真正的事件 private void handleStop(Object view) { ScrollView scroller = (ScrollView) view; System.out.println(scroller.getScrollY()); System.out.println(scroller.getHeight()); //Do Something } }); |