【问题标题】:How to disable scrolling in ScrollView when the viewSwitcher is enabled?启用 viewSwitcher 时如何禁用 ScrollView 中的滚动?
【发布时间】:2013-04-08 06:51:17
【问题描述】:

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

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

【问题讨论】:

    标签: android scrollview viewswitcher


    【解决方案1】:

    try this

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

    像这样为父滚动视图和子 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;
        }
    });
    

    【讨论】:

    • 它不工作。我没有两个滚动视图。我在 Scrollview 中有一个视图切换器。
    • 似乎工作得很好。应该得到绿色复选标记
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 2015-05-22
    相关资源
    最近更新 更多