How to disable scrolling in ScrollView when the vi

2019-07-25 11:28发布

问题:

In my project I am using ScrollView to display list of products and each product will have a sub product. I am using a realviewswitcher to display the sub products. Till this everything works fine . The problem is when I scroll the scrollView it scrolls good .But while using the realviewswitcher to view the sub product (left to right swipe of the list view item) the scrollview is allows gets scrolled. I want to disable the scrollView while swiping left to right . Scrollview must work only when I swipe top to bottom.

I have tried with custom ScrollView.But I didnt get the expected result . I also used setEnabled(false) no use of it . is their any other solutions? please tell me know

回答1:

try this

it will disable scrolling as you want(vertical/horizontal). Or you can try this:

implements setOnTouchListener for both parent scrollview and child realviewswitcher like this:

parentScrollView= (ScrollView) findViewById(R.id.parentScrollview);
parentScrollView.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
         //Log.v(TAG,"PARENT TOUCH");
         findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
        return false;
        }
    });
childScrollView= (ScrollView) findViewById(R.id.childScrollView);
childScrollView.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
         //Log.v(TAG,"PARENT TOUCH");
         findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});