Android scrollview inside another scrollview doesn't scroll

后端 未结 9 561
北恋
北恋 2020-12-10 02:36

I\'m trying to put a ScrollView inside another ScrollView and I tried the answers found on this site but it still doesn\'t seems to work completely. Here is the XML:

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 03:19

    use this custom scrollview as inner scrollview:

    public class TouchMeScrollView extends ScrollView {
    public TouchMeScrollView(Context context) {
        super(context);
    }
    
    public TouchMeScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(ev);
    }
    }
    

提交回复
热议问题