ViewPager 拦截所有 x 轴 onTouch 事件.如何禁用?

ViewPager intercepts all x-axis onTouch events. How to disable?(ViewPager 拦截所有 x 轴 onTouch 事件.如何禁用?)

本文介绍了ViewPager 拦截所有 x 轴 onTouch 事件.如何禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个片段的viewpager.其中一个片段有一个布局,女巫监听 X 轴上的 onTouch 变化.

There is a viewpager of two fragments. One of those fragments has a layout witch listens to onTouch changes at X-axis.

当沿 X 轴触摸和滑动时,布局不会获得几乎所有的 Action.Move 事件.似乎 viewpager 有一个 onInterceptTouchEvent 返回 true.

Layout doesn't get almost all Action.Move events when touching and sliding along X-axis. It seems that viewpager has a onInterceptTouchEvent which returns true.

是否真的要覆盖 viewpager 的行为以使其与我的布局一起工作?所以完美的情况是 layout 拦截了它上面的所有 onTouch 事件,而 viewpager 管理其余的 onTouch 事件.谢谢!

Is it real to override viewpager's behavior to make it and my layout work together? So the perfect situation is layout intercepts all onTouch events on it and viewpager manages the rest of onTouch events. Thanks!

推荐答案

你说得对,我相信每个滚动容器都会拦截触摸事件,但你可以阻止它.您可以在布局上放置一个触摸监听器:

You are right, I believe every scrolling container intercepts touch events, but you can prevent it. You can put a touch listener on your layout:

public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE: 
        pager.requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        pager.requestDisallowInterceptTouchEvent(false);
        break;
    }
}

这篇关于ViewPager 拦截所有 x 轴 onTouch 事件.如何禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ViewPager 拦截所有 x 轴 onTouch 事件.如何禁用?

基础教程推荐