zoukankan      html  css  js  c++  java
  • 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
        }
    });
  • 相关阅读:
    自己用的C++编码规范
    飘逸的python
    编译Sqoop2错误解决
    怎样设置linux中Tab键的宽度(可永久设置)
    系统分析师零散知识点
    Hadoop权威指南学习笔记一
    Spring获取request、session以及servletContext
    RequestContextHolder获取request和response
    Spring MVC 中RequestContextHolder获取request和response
    缓存清理
  • 原文地址:https://www.cnblogs.com/exmyth/p/4516572.html
Copyright © 2011-2022 走看看