view设置setOnTouchListener时,黄牌警告

Custom view `AutoRelativeLayout` has setOnTouchListener called on it but does not override performClick less... (Ctrl+F1)
If a View that overrides onTouchEvent or uses an OnTouchListener does not also implement performClick and call it when clicks are detected, the View may not handle accessibility actions properly. Logic handling the click actions should ideally be placed in View#performClick as some accessibility services invoke performClick when a click action should occur.  Issue id: ClickableViewAccessibility

翻译:

自定义视图“AutoRelativeLayout”调用了setOnTouchListener,但没有覆盖performClick less…(Ctrl + F1)

如果覆盖onTouchEvent或使用OnTouchListener的视图在检测到单击时没有实现performClick并调用它,则视图可能无法正确处理可访问性操作。理想情况下,处理单击操作的逻辑应该放在视图#performClick中,因为当单击操作发生时,一些可访问性服务调用performClick。问题id: ClickableViewAccessibility

 

简单来说,view的调用逻辑是是onTouch-->performClick(该方法源码中调用  onclickListener,如下图),ontouch中返回true了,就会屏蔽onCLickListener的操作。但是看下面源码可知,performClick是publick,如果我们重写了onTouchListener,可以自己判断当前的操作是单击还是滑动,在ACTION_UP的时候,自行调用performClick方法就没问啦。

public boolean performClick() {
        final boolean result;
        final ListenerInfo li = mListenerInfo;
        if (li != null && li.mOnClickListener != null) {
            playSoundEffect(SoundEffectConstants.CLICK);
            li.mOnClickListener.onClick(this);
            result = true;
        } else {
            result = false;
        }

        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);

        notifyEnterOrExitForAutoFillIfNeeded(true);

        return result;
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值