【发布时间】: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