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

前端 未结 2 1306
南旧
南旧 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:

    <com.name.app.MyTimePicker
                    android:id="@+id/timePicker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
    .../>
    

    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;
        }
    }
    
    0 讨论(0)
  • 2020-12-08 23:36

    I had the same problem when using the Holo theme, and here is where I found the solution: https://groups.google.com/forum/?fromgroups#!topic/android-developers/FkSfJI6dH8w

    You must implement your custom DatePicker or TimePicker and override the following method:

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev)
    {
        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
        {
            ViewParent p = getParent();
            if (p != null)
                p.requestDisallowInterceptTouchEvent(true);
        }
    
        return false;
    }
    
    0 讨论(0)
提交回复
热议问题