requestDisallowInterceptTouchEvent不起作用,除非首先选择视图 [英] requestDisallowInterceptTouchEvent does not work unless selecting view first

查看:1004
本文介绍了requestDisallowInterceptTouchEvent不起作用,除非首先选择视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据android的文档,你可以让你的父母的ViewGroup并调用requestDisallowInterceptTouchEvent(真)就可以阻止其他的事情干涉。这导致不仅直接父但可能拦截触摸忽略它的特定事件的持续时间的任何其它的父对象...

According to android docs you can get your parent ViewGroup and call requestDisallowInterceptTouchEvent(true) on it to stop other things from interfering. This causes not only the immediate parent but any other parent objects that might intercept the touch to ignore it for the duration of the particular event...

这听起来很不错,似乎很好地工作在较新的设备(我的是Android 4.1),但较旧的设备(如2.3.3),这是行不通的,除非我点击我的滚动视图,然后再滚动,否则另一方滚动观点仍可能干扰。

This sounds great and seems to work fine on newer devices (mine is android 4.1) but older devices (i.e. 2.3.3) it does not work unless I click on my scroll view first and then scroll it, otherwise other parent scrollable views may still interfere.

我要送的View.OnTouchListener的要求可滚动的孩子。

I'm sending the request in the View.OnTouchListener for the scrollable child.

不知道如何自动使这项工作而不是诉诸编写自定义子类来检查命中RECT上的动作事件,等等?

Any idea how to make this work automatically without resorting to writing custom subclasses to check the hit rect on the motion event, etc?

推荐答案

我遇到了一些问题,也有2.3它的不允许将intermittenltly工作。

I had some problems too with 2.3 where it the disallow would intermittenltly work.

我用来调用event.getAction的view.requestDisallowInterceptTouchEvent(真),无论()。

I used to call view.requestDisallowInterceptTouchEvent(true) regardless of the event.getAction().

然后我试图做一个好公民,并改变了我的code在onTouch()方法如下:

Then I tried to be a good citizen and changed my code in the onTouch() method to the following:

switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            v.requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            v.requestDisallowInterceptTouchEvent(false);
            break;
        default:
            break;
        }

请记住,这个方法(或引用的观点在一些其他视图)必须返回true父母坚持不允许请求。

Remember that this method (or some other views under the referenced view) has to return true for the parents to adhere to the disallow request.

不知道这将解决您的问题,但值得一试。

Not sure this will fix your issue but worth a try.

这篇关于requestDisallowInterceptTouchEvent不起作用,除非首先选择视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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