【问题标题】:View pager onInterceptTouchEvent not generating event查看寻呼机 onInterceptTouchEvent 未生成事件
【发布时间】:2015-02-19 12:03:56
【问题描述】:

我编写了一个自定义 ViewPager,但它没有为 Continuous Action.Move 生成​​事件。触摸它会产生一次 DOWN 和 MOVE 事件 2-3 次,就是这样。然后它不会生成 MOVE 事件。

父 XML 代码。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <example.animation.com.CustomPager
        android:id="@+id/pager"
        android:background="#123456"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



</FrameLayout>

添加子片段 XML 实现:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fmParent"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txtIndex" />

</FrameLayout>

如果我在这里遗漏任何东西,有什么建议。

【问题讨论】:

  • 生成事件?你什么意思?
  • 手指在 ViewPager 上移动不会通过 onInterceptTouchEvent(MotionEvent ev) 生成任何进一步的事件。
  • 如果你返回true,事件被派发到onTouch
  • 是的...这里我需要拦截触摸事件。由于我在这里提到的 Child Fragment 可能是一个列表。据我所知,使用 onInterceptTouchEvent 我必须确定事件是否应该传递给孩子或父母应该处理这个问题。参考:developer.android.com/training/gestures/viewgroup.html
  • 对不起,我不明白你的真正意思

标签: android touch-event xml-layout


【解决方案1】:

可能某些视图会捕获该事件,因此如果只是 ViewPager 应该捕获触摸,您可以更改 ViewPagerfrom 的返回:

return super.onInterceptTouchEvent(ev);

到:

return true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多