android - ViewPager如何禁止滑动,并且其中的子空间仍然可以响应点击事件?
阿神
阿神 2017-04-17 15:48:10
0
4
572

网上找到的禁止滑动答案是在dispathchTouchEvent()方法里返回true,但是这样,其中的子控件也无法响应点击事件了。有人说重写子控件,使用getParent().requestDisallowInterceptTouchEvent()设置ViewPager不拦截点击事件。但是我有很多子控件,该如何实现这样的需求呢?

阿神
阿神

闭关修行中......

reply all(4)
迷茫

Rewrite ViewPager

@Override     
public boolean onTouchEvent(MotionEvent ev) {         
    return isScrollable && super.onTouchEvent(ev);     
}

@Override     
public boolean onInterceptTouchEvent(MotionEvent ev) {
     return isScrollable && super.onInterceptTouchEvent(ev);     
}

isScrollable is whether sliding is allowed, preventing Viewpager events, and child controls can also respond to events

左手右手慢动作

Rewrite touch events to cancel left and right sliding. Note that the overridden object is ViewPager, not Activity.

mRecoverPwdVp.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});
大家讲道理

In the previous question of the questioner, I mentioned that this problem is actually about the understanding of touch event distribution. Google the distribution mechanism of touch events, and then you can look back at this issue after understanding it. Hope this helps!

小葫芦

Rewrite ViewPager as follows

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return false;//不要拦截事件   事件要分发给后面的控件
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return false;//不自己去处理事件
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template