Reputation: 31
I have a webview and ViewPager in LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/webview_wrapper"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.view.ViewPager
android:id="@+id/slide_page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#696969"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
While I set OnTouchListener on both webview and ViewPager. I try to start drag on webview and pass the MotionEvent to viewPager when I am in dragging.
My code is as below.
WebView mainView = tab.getWebView();
mainView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
Log.w("LOGTAG", "onTouch");
switch (e.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.w("LOGTAG", "ACTION_UP");
break;
case MotionEvent.ACTION_MOVE:
Log.w("LOGTAG", "ACTION_MOVE");
Test(...);
mPager.dispatchTouchEvent(e);
break;
case MotionEvent.ACTION_UP:
Log.w("LOGTAG", "ACTION_UP");
break;
}
return false;
}
});
private void Test(...) {
FrameLayout wrapper =
(FrameLayout) container.findViewById(R.id.webview_wrapper);
mPager = (ViewPager)container.findViewById(R.id.slide_page);
...
wrapper.setVisibility(View.GONE);
mPager.setVisibility(View.VISIBLE);
mPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
Log.w("LOGTAG", "mPager.onTouch");
switch (e.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.w("LOGTAG", "mPager.ACTION_DOWN");
break;
case MotionEvent.ACTION_MOVE:
Log.w("LOGTAG", "mPager.ACTION_MOVE");
break;
case MotionEvent.ACTION_UP:
Log.w("LOGTAG", "mPager.ACTION_UP");
break;
}
return false;
}
});
}
Here is my log:
...
08-06 07:09:16.321: W/(26460): mPager.dispatchTouchEvent(e) = true
08-06 07:09:16.321: W/(26460): onTouch
08-06 07:09:16.321: W/(26460): ACTION_MOVE
08-06 07:09:16.321: W/(26460): mPager.onTouch
08-06 07:09:16.321: W/(26460): mPager.ACTION_MOVE
...
ViewPager onTouchListener detected MotionEvent well, but viewpager did not move.
Any help will be greatly appreciated.
Upvotes: 1
Views: 4258
Reputation: 31
I solve this problem. I overrided onTouch method of Viewpager, and nothing did in my onTouch method. So viewpager received touch event but didn't move. when I removed TouchListener which I overrided, and it worked well.
Upvotes: 2