2013-09-06 2 views
7

이 문제를 해결하기 위해 노력하고 있습니다 : How to disable pullToRefreshScrollView from listening to touch 거기에 대한 솔루션을 사용자 정의 가능한 클래스를 만들지 않고 OnTouchEvents 처리 ScrollView 차단하려면 궁금한가요? ScrollView 스크롤을 사용 중지하는 방법은 무엇입니까?

gridView.getParent().requestDisallowInterceptTouchEvent(true); 

mScrollView.setOnTouchListener(new OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       return false; 
      } 
     }); 

같은 모든 Methos는 작동하지 않는 이유는 무엇입니까? 그들에게 어떤 문제가 있습니까? Google이 작동하지 않는 방법을 구현하는 이유는 무엇입니까?

답변

18

// 아무것도를하지 않는다하는 OnTouchListener를 설정하여있는 ScrollView

final ScrollView myScroll = (ScrollView) findViewById(R.id.display_scrollview); 

// 해제 스크롤을 얻기

myScroll.setOnTouchListener(new OnTouchListener(){ 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     return true; 
    } 
}); 

// OnTouchListner

tvDisplayScroll.setOnTouchListener(null);  
+4

호출 레이아웃이 될 수 있습니다 사용, 그것은 작동하지 않습니다. –

+0

작동하지만 지금 중첩 된 scrollview 중 하나를 스크롤 할 수 없습니다 .. – DrNachtschatten

6

을 제거하여 스크롤을 사용 사용해보고 :

 scrollView.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 
      return isBlockedScrollView; 
     } 
    }); 
8

사용자 정의 ScrollView를 만들고 원하는 곳 어디에서나 사용할 수 있습니다.

class CustomScrollView extends ScrollView { 

    // true if we can scroll the ScrollView 
    // false if we cannot scroll 
    private boolean scrollable = true; 

    public void setScrollingEnabled(boolean scrollable) { 
     this.scrollable = scrollable; 
    } 

    public boolean isScrollable() { 
     return scrollable; 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     switch (ev.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       // if we can scroll pass the event to the superclass 
       if (scrollable) return super.onTouchEvent(ev); 
       // only continue to handle the touch event if scrolling enabled 
       return scrollable; // scrollable is always false at this point 
      default: 
       return super.onTouchEvent(ev); 
     } 
    } 

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

} 

<com.packagename.CustomScrollView 
    android:id="@+id/scrollView" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

</com.packagename.CustomScrollView > 

가 그럼 난이 솔루션을 붙여 넣은

((CustomScrollView)findViewById(R.id.scrollView)).setIsScrollable(false); 
+0

네,이 작동하지만 위에 입력 한 것처럼이 솔루션을 피하기 위해 노력하고있어. 어쨌든 고마워 –

+2

this.scrollable = scrollable; –

+0

두 가지 대체 메소드는 다음과 같이 단순화 할 수 있습니다. public boolean onTouchEvent (MotionEvent ev) {return! false : super.onTouchEvent (ev); }'onIntercept와 동일하게 ... – Pierre

관련 문제