0

I tried wihout success to disable a vertical ScrollView for a specific angle.

The goal behind this is to handle properly multiple horizontal ListView nested in a vertical ScrollView.

I tried this but it's not working :

public class VScrollView extends ScrollView {

    private GestureDetector mGestureDetector;
    View.OnTouchListener mGestureListener;

    public VScrollView(Context context) {
        super(context);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
        setFadingEdgeLength(0);
    }

    public VScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
        setFadingEdgeLength(0);
    }

    public VScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
        setFadingEdgeLength(0);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
    }


    class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (e1 != null && e2 != null) {
                double delta_x = (e1.getX() - e2.getX());
                double delta_y = (e1.getY() - e2.getY());
                double radians = Math.abs(Math.toDegrees(Math.atan2(delta_y, delta_x)));
                if (radians > 80 && radians < 100) {
                    return true;
                }
            }
            return false;
        }
    }
}
ForceMagic
  • 6,230
  • 12
  • 66
  • 88

1 Answers1

1

I know that's probably what you don't want to hear, but Google keep asking us not doing that.

Refer to this SO question which basically quote Google saying

You should never use a HorizontalScrollView with a ListView [...]

Community
  • 1
  • 1
ForceMagic
  • 6,230
  • 12
  • 66
  • 88