如何让 onTouch 在 ViewPager 后面的视图上被调用?
How to get onTouch to be called on a view behind a ViewPager?
我有一个 ViewPager
背后的观点。此视图使用 OnTouchListener
垂直上下滑动。这在显示部分视图时效果很好,但我想这样做,以便用户可以从 ViewPager
的顶部向下滑动以显示此视图。我已经尝试子类化 ViewPager
并在 onInterceptTouchEvent
中返回 false,但它没有用。我还尝试将此 OnTouchListener
添加到 ViewPager
本身作为 hack,但这也不起作用。
下面的图片代表了我正在努力实现的目标。
Collapsed View behind ViewPager
Swiping View from behind the ViewPager
这是我一直在测试的简单布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/content"
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="128dp" />
</RelativeLayout>
尝试在ViewPager的触摸事件上模拟View的触摸事件,按照这个模拟触摸事件,
How to programmatically trigger the touch event in android?。
让我知道这是否有效。
我有一个 ViewPager
背后的观点。此视图使用 OnTouchListener
垂直上下滑动。这在显示部分视图时效果很好,但我想这样做,以便用户可以从 ViewPager
的顶部向下滑动以显示此视图。我已经尝试子类化 ViewPager
并在 onInterceptTouchEvent
中返回 false,但它没有用。我还尝试将此 OnTouchListener
添加到 ViewPager
本身作为 hack,但这也不起作用。
下面的图片代表了我正在努力实现的目标。
Collapsed View behind ViewPager
Swiping View from behind the ViewPager
这是我一直在测试的简单布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/content"
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="128dp" />
</RelativeLayout>
尝试在ViewPager的触摸事件上模拟View的触摸事件,按照这个模拟触摸事件, How to programmatically trigger the touch event in android?。 让我知道这是否有效。