Снощи добавях view pager в контейнер от scrollview и тъй като не е много препоръчително да се прави естествено държанието на цялото приложение беше "странно", проблема го реших със следното парченце код:
final ViewPager vp = (ViewPager) findViewById(R.id.top_imageViewPager);
vp.setPageMargin(-50);
vp.setHorizontalFadingEdgeEnabled(false);
vp.setFadingEdgeLength(30);
adapter = new ImageViewAdapterClubObekt(cnt, snimki_top);
vp.setAdapter(adapter);
vp.setOnTouchListener(new View.OnTouchListener() {
int dragthreshold = 30;
int downX;
int downY;
@Override
public boolean onTouch(View v, MotionEvent event) {
ScrollView mScrollView = (ScrollView) findViewById(R.id.scrrol_view_obekt);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = (int) event.getRawX();
downY = (int) event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int distanceX = Math.abs((int) event.getRawX() - downX);
int distanceY = Math.abs((int) event.getRawY() - downY);
if (distanceY > distanceX && distanceY > dragthreshold) {
vp.getParent().requestDisallowInterceptTouchEvent(false);
mScrollView.getParent().requestDisallowInterceptTouchEvent(true);
} else if (distanceX > distanceY && distanceX > dragthreshold) {
vp.getParent().requestDisallowInterceptTouchEvent(true);
mScrollView.getParent().requestDisallowInterceptTouchEvent(false);
}
break;
case MotionEvent.ACTION_UP:
mScrollView.getParent().requestDisallowInterceptTouchEvent(false);
vp.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
vp.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
break;
default:
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
break;
}
}
});
Освен проблема с свайп евентите съм "фикснал" и лявото меню да не се показва при swipe ако елемента не е 0-ев.
За лявото меню ползвам "SlidingMenu"