在scrollView中向左和向右滑动

时间:2015-02-28 22:16:49

标签: android scrollview swipe

我在scrollView中有一些布局。那些布局必须是'#34;可转换的"在左右方向但它与scrollView创建了一些冲突。

我尝试在触摸其中一个布局时禁用scrollView,但在这种情况下,我的scrollView几乎总是禁用。

这就是我的布局。

enter image description here

我现在的目标:

private void swipePositionsEvent() {
    for(LinearLayout layout : layouts){
        layout.setOnTouchListener(new OnSwipeTouchListener(this,
                ((ScrollView)findViewById(R.id.scroll_view_confirm_games))){
            public void onSwipeRight() {
                flipper.showNext();
            }
            public void onSwipeLeft() {
                flipper.showPrevious();
            }
        });
   }

在OnSwipeTouchListener中:

    Override
    public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            // Disallow ScrollView to intercept touch events.
            scrollView.requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow ScrollView to intercept touch events.
            scrollView.requestDisallowInterceptTouchEvent(false);
            break;
        }
        return gestureDetector.onTouchEvent(event);
    }

谢谢!

1 个答案:

答案 0 :(得分:0)

在禁用滚动视图之前检测第一个移动是水平还是垂直。

相关问题