2013-05-15 1 views
3

나는 scrollview 안에 onClickListener가있는 뷰를 가지고 있습니다. 보기는 클릭에 반응해야하지만 스크롤보기는 거의 모든 터치를 ACTION_MOVE로 해석하고 터치 이벤트를 가로 채기 때문에보기를 클릭 할 수 없습니다. (그것은 viewpager에 있기 때문에 그리고 viewpager 스크롤하지 않도록해야합니다) 다음안드로이드 ScrollView 클릭 수를 가로 채기,하지 말아야합니다

@Override 
public boolean onInterceptTouchEvent(MotionEvent p_event) { 
    if (p_event.getAction() == MotionEvent.ACTION_MOVE) { 
     return true; 
    } 
    return super.onInterceptTouchEvent(p_event); 
} 

@Override 
public boolean onTouchEvent(MotionEvent p_event) { 
    if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) { 
     getParent().requestDisallowInterceptTouchEvent(true); 
    } 
    return super.onTouchEvent(p_event); 
} 

가 어떻게 ACTION_MOVE로 가장 작은 움직임을 등록하지 할 수있는 ScrollView의 감도를 변경할 수 있습니다로

나는 내있는 ScrollView을 수정 한 터치 이벤트를 자녀에게 전달할 수 있습니까?

도움 주셔서 감사합니다.

답변

2

신경 쓰지 마라, 고쳤다. 잘 작동 다음과 같이 코드를 수정하면 첫 번째 부분은 필요하지 않습니다 :

이 대단한
@Override 
public boolean onInterceptTouchEvent(MotionEvent p_event) { 
    /*if (p_event.getAction() == MotionEvent.ACTION_MOVE) { 
     return true; 
    }*/ 
    return super.onInterceptTouchEvent(p_event); 
} 

@Override 
public boolean onTouchEvent(MotionEvent p_event) { 
    if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) { 
     getParent().requestDisallowInterceptTouchEvent(true); 
    } 
    return super.onTouchEvent(p_event); 
} 
+0

, 감사,하지만 나를 위해 타협이다. 나는 ScrollView 안에 10 명의 자식을 가지고 있으며, 이것으로 모두 동일한 클릭 핸들러를 설정해야한다. 이상적으로, 나는 내 ScrollViews 부모 (또는 심지어 ScrollView 자체)가 클릭에 응답하고 싶습니다만, 나는 그 경우에 대해 작동하도록 할 수 없습니다. 스크롤 기능이 작동하거나 클릭 기능이 작동하지만 동시에 두 가지 기능을 동시에 사용할 수는 없습니다. – RTF