Scrollview doesn't swipe when it's too short to scroll

前端 未结 3 846
死守一世寂寞
死守一世寂寞 2021-01-05 02:28

I\'m pretty new to Android app development, and I\'ve been playing around with swipe gestures using Android\'s SimpleOnGestureListener and a ViewFlipper. There are 3 childr

相关标签:
3条回答
  • 2021-01-05 02:51

    Try setting android:fillViewport="true" in your layout xml for each of the ScrollViews. That tells the ScrollView to be as large as the view it's contained in.

    0 讨论(0)
  • 2021-01-05 02:54

    Had the same issue. You need to intercept the touch event on the children of the ScrollView when it's too short to have a scrollbar.

    0 讨论(0)
  • 2021-01-05 03:04

    I needed to create a new class that extended ScrollView, and used this:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
        return gestureDetector.onTouchEvent(event);
    }
    
    @Override 
    public boolean dispatchTouchEvent(MotionEvent ev){
        gestureDetector.onTouchEvent(ev);
        super.dispatchTouchEvent(ev); 
        return true;
    } 
    

    I have no idea why, but if I try to return anything but true in dispatchTouchEvent (the logical thing would have been to

    return (gestureDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev)); 
    

    if I understand properly), it doesn't work, and this does.

    0 讨论(0)
提交回复
热议问题