View pager onInterceptTouchEvent not generating ev

2019-09-18 13:31发布

问题:

I have written an custom ViewPager but it's not generating event for Continuous Action.Move. On touch it generate DOWN once and MOVE event 2-3 time and that's it. Then after it not generate MOVE event.

Parent XML code.

<?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>

Added Child Fragment XML implementation:

<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>

Any suggestion if I am missing anything here.

回答1:

Probably some view catch the event, so if just the ViewPager should catch the touches you can change the return of the ViewPagerfrom:

return super.onInterceptTouchEvent(ev);

to:

return true;