Android TimePicker (Wheel Style) not responding correctly to flick gestures inside ScrollView

前端 未结 2 1308
南旧
南旧 2020-12-08 22:58

I have a dialog box that contains a Scrollview, which contains a layout with two TimePickers.

The timepickers are the newer style ones, what\'s in ICS.

The p

2条回答
  •  旧巷少年郎
    2020-12-08 23:22

    Because the link from Klemens Zleptnig is broken, here is a complete example. This fix helps with the scroll of a TabLayout too btw. I excluded the area around the big numbers in the top of the TimePicker because they don't need the scroll event anyway.

    xml:

    
    

    java:

    public class MyTimePicker extends TimePicker {
        public MyTimePicker(Context context) {
            super(context);
        }
    
        //This is the important constructor
        public MyTimePicker(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public MyTimePicker(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public MyTimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev)
        {
            if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
            //Excluding the top of the view
                if(ev.getY() < getHeight()/3.3F)
                    return false;
    
                ViewParent p = getParent();
                if (p != null)
                    p.requestDisallowInterceptTouchEvent(true);
            }
    
            return false;
        }
    }
    

提交回复
热议问题