2

I create Scrollview with 10 layout. I want to change the layout position by dragging.

layout_view.setOnTouchListener(new View.OnTouchListener() { 

@Override

public boolean onTouch(View v, MotionEvent ev) {
final int action = ev.getAction();  

switch (action) {   
case MotionEvent.ACTION_DOWN: {
...

The problem is when i dragging DOWN/UP (When I dragging right/left it's work perfect):

1) MotionEvent.ACTION_CANCEL happen

2) the Scrollview is moving

1)How Can I disable Scrollview scrolling when I dragging my layout?

2) Do you have any idea how to stay in layout without getting MotionEvent.ACTION_CANCEL?

Thanks

Sam
  • 1,509
  • 3
  • 19
  • 28
user434779
  • 21
  • 3
  • This is not a feature that will be easily (if at all) implemented as far as I know. You could try setting the scrollview as not focusable. – Falmarri Aug 30 '10 at 10:22

1 Answers1

1

Override ScrollView with one that you can enable/disable

//A scrollview which can be disabled during drag and drop
public static class OnOffScrollView extends ScrollView {
    private boolean on = true;
    public OnOffScrollView(Context context) {
        super(context);
    }

    public OnOffScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

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

    //turn on the scroll view
    public void enable() {
        on=true;
    }

    //turn off the scroll view
    public void disable() {
        on = false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (on) {
            return super.onInterceptTouchEvent(ev);
        }
        else {
            return false;
        }
    }
}

Disable it in your MotionEvent.ACTION_DOWN case, enable it again in the MotionEvent.ACTION_CANCEL and MotionEvent.ACTION_UP cases

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Chad Autry
  • 11
  • 1