calendarview stops scrolling when nested in scrollview in android

前端 未结 2 2007
盖世英雄少女心
盖世英雄少女心 2021-01-14 00:06

I have nested calendarview in ScrollView . My problem begins when height of view increases. I can scroll calendar months vertically but when scrollview

2条回答
  •  温柔的废话
    2021-01-14 00:27

    I've found answer to this problem here: https://stackoverflow.com/a/9687545

    Basically you need to implement custom CalendarView and override onInterceptTouchEvent method. I did it as following:

    package com.example.app.views;
    
    public class CalendarViewScrollable extends CalendarView {
    
        public CalendarViewScrollable(Context context) {
            super(context);
        }
    
        public CalendarViewScrollable(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CalendarViewScrollable(Context context, AttributeSet attrs,
                int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev)
        {
            if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
            {
                ViewParent p = getParent();
                if (p != null)
                    p.requestDisallowInterceptTouchEvent(true);
            }
    
            return false;
        }
    
    }
    

    Then just use this view in XML layout file:

    
    

提交回复
热议问题