在我们自定义viewgroup时,如果你自定义的viewGrope不是滑动的ViewGrop,可以从写他的shouldDelayChildPressedState方法返回false,默认返回true,系统会做个延迟100ms响应子view事件操作,
//下面是源码注释
/**
* Return true if the pressed state should be delayed for children or descendants of this
* ViewGroup. Generally, this should be done for containers that can scroll, such as a List.
* This prevents the pressed state from appearing when the user is actually trying to scroll
* the content.
*
* The default implementation returns true for compatibility reasons. Subclasses that do
* not scroll should generally override this method and return false.
*/
public boolean shouldDelayChildPressedState() {
return true;
}
翻译:
/ * *
*如果按下的状态应该为this的子代或子代延迟返回true
* ViewGroup。一般来说,这应该用于可以滚动的容器,比如列表。
*这防止了按下状态出现时,用户实际上是试图滚动
*内容。
*
*出于兼容性考虑,默认实现返回true。子类,
* not scroll通常应该覆盖这个方法并返回false。
* /
//优化后代码
@Override public boolean shouldDelayChildPressedState() {
return false;
}