I need to place HorizontalScrollView inside ViewPager. Every child of ViewPager is ScrollView with HorizontalScrollView inside. I zoom child of HorizontalScrollView. After it I need to allow user to scroll HorizontalScrollView but not to scroll to the next page of ViewPager. To handle action I create custom ViewPager:
public class MyViewPager extends ViewPager {
private static final String TAG = MyViewPager.class.getName();
public MyViewPager(Context context) {
super(context);
}
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
final int action = MotionEventCompat.getActionMasked(ev);
// Always handle the case of the touch gesture being complete.
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
return super.onInterceptTouchEvent(ev); // Do not intercept touch event, let the child handle it
}
switch (action) {
case MotionEvent.ACTION_MOVE: {
ViewGroup view=(ViewGroup)(getChildAt(getCurrentItem()));
if (view.getChildCount()>0) {
view = (ViewGroup) view.getChildAt(0);
if (view instanceof CustomHorizontalScroll) {
CustomHorizontalScroll scroll = (CustomHorizontalScroll) view;
if (((CustomHorizontalScroll) view).isZoom()) {
return false;
} else {
return true;
}
}
}
break;
}
default: return super.onInterceptTouchEvent(ev);
}
}catch (Exception e){
return super.onInterceptTouchEvent(ev);
}
return super.onInterceptTouchEvent(ev);
}
}
The problem is with onTouchAction. In my horizontal view there are onClick events. If I use custom ViewPager then sometimes onClick dont work. Whet I need to do? How to work with ActionDown in this situation?