How to disable scolling in HorizontalScrollView?

I have a HorizontalScrollView and a button in my project. I want this to → -> when the button pressed the HorizontalScrollView button, don't scroll. The real user can commit the view.

I use this code, but it does not work.

Button btn_s = (Button) findViewById(R.id.button999); final HorizontalScrollView h_scroll = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1); btn_s.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { h_scroll.setVisibility(0); } }) 
+4
source share
2 answers

I solved this problem with this code:

  Button btn_s = (Button) findViewById(R.id.button999); final HorizontalScrollView h_scroll = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1); btn_s.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(!return_h_scroll){ return_h_scroll = true; } else return_h_scroll = false; } }); h_scroll.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return return_h_scroll; } }); 
0
source

you can use

 h_scroll.setVisibility(View.INVISIBLE); h_scroll.setVisibility(View.GONE); 

In addition, you can define your behavior to view scrolling using the function

 public boolean onInterceptTouchEvent(MotionEvent ev) { } 

Look here Intercept horizontal scroll

+4
source

All Articles