打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Activity 的 dispatchTouchEvent
   /**
     * Called to process touch screen events.  You can override this to
     * intercept all touch screen events before they are dispatched to the
     * window.  Be sure to call this implementation for touch screen events
     * that should be handled normally.
     *
     * @param ev The touch screen event.
     *
     * @return boolean Return true if this event was consumed.
     */

   // Activity 对于callBack 接口方法的实现
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // down 事件 回调onUserInteraction() ,空方法
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
        }
        // getWindoe() 返回的就是PhoneWindow 实例
        // 直接调用PhoneWindow的方法
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        // 如果前面分发过程中国呢的事件没有被处理,那么调用Activity自身的方法对事件进行处理
        return onTouchEvent(ev); 
    }



    /**
     * Called when a touch screen event was not handled by any of the views
     * under it.  This is most useful to process touch events that happen
     * outside of your window bounds, where there is no view to receive it.
     *
     * @param event The touch screen event being processed.
     *
     * @return Return true if you have consumed the event, false if you haven't.
     * The default implementation always returns false.
     */
    public boolean onTouchEvent(MotionEvent event) {
        if (mWindow.shouldCloseOnTouch(this, event)) {
            finish();
            return true;
        }

        return false;
    }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android中的Touch事件
Android源码分析
Android FrameWork——Touch事件派发过程详解
Android事件传递机制
Android图片放大后左右滑动时,viewpager与ImageView冲突
Android事件分发机制二:viewGroup与view对事件的处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服