4

I've already tried:

 scrollView.setEnable(false);

 scrollView.setOnTouchListener(null);

 scrollView.requestDisallowInterceptTouchEvent(true);

but none of these worked... I can't understand why, is there any other way to do it?

scrollView in xml:

<ScrollView
    android:id="@+id/mainPage_scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:focusableInTouchMode="true"
    android:layout_below="@+id/tabBar" >

</ScrollView>
THelper
  • 15,333
  • 6
  • 64
  • 104
yahya
  • 4,810
  • 3
  • 41
  • 58

2 Answers2

4

For future reference a much simpler solution that I use for a 'drawable area within a ScrollView' is to use requestDisallowInterceptTouchEvent to tell the parent and up the chain not to interfere with the touch actions.

eg on the drawable View, where the parent in this case is the LinearLayout inside the ScrollView but could also be nested in other components:

@Override
public boolean onTouchEvent(MotionEvent event)
{
    if (event.getAction() == MotionEvent.ACTION_DOWN)
    {
        this.parent.requestDisallowInterceptTouchEvent(true);
        // etc...
    }
    else if(event.getAction() == MotionEvent.ACTION_MOVE)
    {
        // etc...
    }
    else if (event.getAction() == MotionEvent.ACTION_UP)
    {
        this.parent.requestDisallowInterceptTouchEvent(false);
        // etc...
    }
    return true;
}
David O'Meara
  • 2,983
  • 25
  • 38
3

There is no direct way to stop scrollview to scroll but u can do it in other way Like:

scrollview.setOnTouchListener(new OnTouchListener() 
{

  @Override
  public boolean onTouch(View v, MotionEvent event) 
  {

  return !enable;
  }
});

when you set enable variable to true it will start scrolling and when you set it to false it stop scrolling.