I've a activity which has a ViewPager and each Page is fragment having Zoomable imageView. I've implemented drag to close feature using onTouch method on parent view of zoomable imageView and drag is working fine. But i want to check if there are 2 figures detected in dispatchTouchEvent then ignore onTouch method and pass touch to child views so i can zoom image. I've tried writing a class as following but it doesn't work. How can i resolve the issue? So, zoom and drag don't conflict with each other.
Thanks
CustomView:
public class DraggableRelativeLayout extends RelativeLayout {
private final int THRESHOLD = ScreenUtils.dpToPx(10);
float diffX, diffY;
private float initialXValue;
private float initialYValue;
public DraggableRelativeLayout(Context context) {
super(context);
}
public DraggableRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DraggableRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public DraggableRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
initialXValue = ev.getX();
initialYValue = ev.getY();
// return false;
break;
case MotionEvent.ACTION_MOVE:
diffX = ev.getX() - initialXValue;
diffY = ev.getY() - initialYValue;
if (Math.abs(diffY) <THRESHOLD || ev.getPointerCount() > 1)
return true;
else
return super.dispatchTouchEvent(ev);
//break;
case MotionEvent.ACTION_UP:
break;
}
return super.dispatchTouchEvent(ev);
}
}
onTouchListener:
public class PostDetailTouchListener implements View.OnTouchListener {
public PostDetailTouchListener(Context context, View view, View viewToZoom, OnDragInteractionListener mListener) {
dragView = view;
dragListener = mListener;
zoomView = viewToZoom;
}
@Override
public boolean onTouch(View view2, MotionEvent event) {
// doing my work
}
you can achieve this using gesture detector for detail link