How to disable scrolling in ScrollView when the viewSwitcher is enabled?

最后都变了- 提交于 2019-12-24 09:55:51

问题


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;
    }
});


来源:https://stackoverflow.com/questions/15872944/how-to-disable-scrolling-in-scrollview-when-the-viewswitcher-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!