SeekBar in a NavigationDrawer

前端 未结 2 792
花落未央
花落未央 2021-02-18 18:34

I want to use a seekbar in a Navigation Drawer

Basically I need to slide left and right to set the seekbar and, well, you guessed it, it slides the navigation drawer...<

2条回答
  •  难免孤独
    2021-02-18 19:10

    Use DrawerLayout.setDrawerLockMode

    instead of ViewParent.requestDisallowInterceptTouchEvent.

    In @dumazy answer requestDisallowInterceptTouchEvent solves this issue but it also creates another.

    While you are scrolling on navigation drawer, If you touch on SeekBar, OnSeekBarChangeListener will trigger. So scrolling event will break and seekbar progress will start to change by moving your finger.

    I modified the original answer a little bit to solve this issue using DrawerLockMode:

    mSeekBar.setOnTouchListener(new SeekBar.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
    
                case MotionEvent.ACTION_DOWN:
                    // Disallow Drawer to intercept touch events.
                    // v.getParent().requestDisallowInterceptTouchEvent(true);
                    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
                    break;
    
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    // Allow Drawer to intercept touch events.
                    // v.getParent().requestDisallowInterceptTouchEvent(false);
                    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
                    break;
            }
    
            // Handle SeekBar touch events.
            v.onTouchEvent(event);
            return true;
        }
    });
    

提交回复
热议问题