自定义viewGroup优化点击响应小技巧

在我们自定义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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值