如何在启用viewSwitcher时禁用ScrollView中的滚动?

时间:2013-04-08 06:51:17

标签: android scrollview viewswitcher

在我的项目中,我使用ScrollView显示产品列表,每个产品都有一个子产品。我正在使用realviewswitcher来显示子产品。直到这一切都运行正常。问题是当我滚动scrollView它滚动得很好。但是当使用realviewswitcher查看子产品时(从左到右滑动列表视图项),scrollview允许滚动。我想在从左向右滑动时禁用scrollView。 Scrollview只有在我从上到下滑动时才能工作。

我尝试过使用自定义ScrollView.But我没有得到预期的结果。我也使用setEnabled(false)没有使用它。是他们的其他解决方案吗?请告诉我知道

1 个答案:

答案 0 :(得分:2)

try this

它会根据需要禁用滚动(垂直/水平)。 或者你可以试试这个:

为父scrollview和子realviewswitcher实现setOnTouchListener,如下所示:

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