Search code examples
javaandroidandroid-scrollview

make Scrollview unscrollable android studio


i have three horizontal scrollviews in one activity:

HorizontalScrollView eventScroll;
HorizontalScrollView heavenScroll;
HorizontalScrollView bottomScroll;

i want the user to only be able to use eventScroll and the two others should set their x position depending what x position eventScroll has like this:

    eventScroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            int scrollX = eventScroll.getScrollX();

            heavenScroll.setScrollX(scrollX / 5);
            bottomScroll.setScrollX(scrollX * 3);


        }
    });

now my problem is the user can still scroll on the other scrollviews for a sec or so before the x position reset itself to correct value, so i would like to disable the other scrollviews for the user but i still want the mot be able to change ScrollX value.


Solution

  •     heavenScroll.setOnTouchListener(new View.OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                return true;
            }
        });