Skip to content Skip to sidebar Skip to footer

Disable Vertical Scroll When User Scrolling Horizontally In Android

I have a vertical custom list and each item of vertical list contains a horizontal list-view. When I scroll horizontally then list also moves little vertically. Which makes it less

Solution 1:

The idea is to disable the parent listview to intercept touch event. This might work :

HorizontalListView hv = (HorizontalListView)findViewById(R.id.hlistview);  
    hv.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ListView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;

                case MotionEvent.ACTION_UP:
                    // Allow ListView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }

                // Handle HorizontalScrollView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });

Reference : https://stackoverflow.com/a/22609646/1239966


Solution 2:

Best way to do this.

put given code on your horizontal listview onScroll method it work perfact

ViewParent view_parent = getParent();
if (view_parent != null) 
{
 view_parent.requestDisallowInterceptTouchEvent(true);
}

Post a Comment for "Disable Vertical Scroll When User Scrolling Horizontally In Android"