1

For example, when I move the circleseekbar slider, the scrollview also works, thereby moving the entire layout up, and I just need to be able to change the position of the slider.

Tried it through android:scrollbars = "none" - everything also failed.

Arsen Tagaev
  • 411
  • 7
  • 13

1 Answers1

4

You need to temporary stop the ScrollView scrolling and re-enable it when you're done manipulating the SeekBar.

To achieve that: Instead of using ScrollView, use the below customized one where Overriding onInterceptTouchEvent did the trick.

public class LockableScrollView extends ScrollView {

    // true if we can scroll (not locked)
    // false if we cannot scroll (locked)
    private boolean mScrollable = true;

    public LockableScrollView(Context context) {
        super(context);
    }

    public LockableScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LockableScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setScrollingEnabled(boolean enabled) {
        mScrollable = enabled;
    }

    public boolean isScrollable() {
        return mScrollable;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {// if we can scroll pass the event to the superclass
            return mScrollable && super.onTouchEvent(ev);
        }
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // Don't do anything with intercepted touch events if
        // we are not scrollable
        return mScrollable && super.onInterceptTouchEvent(ev);
    }
}

You can temporary stop the scrolling when you touch the SeekBar by calling myScrollView.setScrollingEnabled(false); and enable it when you lift the finger off the Seekbar as below

seekBar.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
            myScrollView.setScrollingEnabled(false);
        else if (event.getAction() == MotionEvent.ACTION_UP)
            myScrollView.setScrollingEnabled(true);
        return false;
    }
});

Reference of LocableScrollView

Zain
  • 37,492
  • 7
  • 60
  • 84
  • 1
    Thanks for the answer, all works fine. And I appeal to future visitors: don't forget set custom scrollview in XML file, like in reference on top – Arsen Tagaev Jan 04 '21 at 05:40