b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

触摸屏虚拟键盘 Android Touch事件传递机制全面解析(从WMS到View树)(5)

电脑杂谈  发布时间:2018-02-19 12:20:49  来源:网络整理

dispatchTouchEvent方法。终于也是会调用到super.dispatchTouchEvent。我们能够继续往下看Activity的dispatchTouchEvent方法:

    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }

前面if分支不用管,这里会调用PhoneWindow的superDispatchTouchEvent方法。进去看看:

    @Override
    public boolean superDispatchTouchEvent(MotionEvent event) {
        return mDecor.superDispatchTouchEvent(event);
    }

调用了DecorView的superDispatchTouchEvent方法,再进去看看:

        public boolean superDispatchTouchEvent(MotionEvent event) {
            return super.dispatchTouchEvent(event);
        }

终于还是调用来DecorView的super.dispatchTouchEvent。也就是说。不管如何。DecorView的dispatchTouchEvent终于都会调用到自己父亲FrameLayout的dispatchTouchEvent方法。而我们在FrameLayout中找不到dispatchTouchEvent方法。所以,会去运行ViewGroup的

诺基亚触屏虚拟键盘_触摸屏虚拟键盘_触摸屏软键盘

dispatchTouchEvent方法。

假设该dispatchTouchEvent返回true,说明后面有view消费掉了该事件,那就返回true,不会再去运行自身的onTouchEvent方法,否则,说明没有view消费掉该事件,会一路回传到Activity中,然后调用自己的onTouchEvent方法。该方法的实现比较简单。例如以下:

    public boolean onTouchEvent(MotionEvent event) {
        if (mWindow.shouldCloseOnTouch(this, event)) {
            finish();
            return true;
        }
        
        return false;
    }

    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-84984-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...