1
ScrollView에 스 와이프 기능을 추가하고 싶습니다 (왼쪽 및 오른쪽에서 오른쪽 방향). 모든 터치 이벤트를 차단하지 않고 하위 버튼을 계속 클릭 할 수 있습니다. ScrollView 왼쪽/오른쪽 스 와이프 구현
는이 같은 스크롤 뷰에 터치 리스너를 추가 :this.getView().findViewById(R.id.scrollView1).setOnTouchListener(new OnSwipeTouchListener() {
public void onSwipeTop() {
Toast.makeText(DetailFragment.this.getActivity(), "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight() {
Toast.makeText(DetailFragment.this.getActivity(), "right", Toast.LENGTH_SHORT).show();
}
public void onSwipeLeft() {
Toast.makeText(DetailFragment.this.getActivity(), "left", Toast.LENGTH_SHORT).show();
}
public void onSwipeBottom() {
Toast.makeText(DetailFragment.this.getActivity(), "bottom", Toast.LENGTH_SHORT).show();
}
});
그 다음 내 터치 리스너가 호출되지 않습니다,처럼 나는 그것을 할 경우. 그래서 내 생각은
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean intercept = false;
final int action = ev.getAction();
ViewConfiguration vc = ViewConfiguration.get(this.getContext());
int slop = vc.getScaledTouchSlop();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP: {
float currX = ev.getX();
if (Math.abs(currX - originalX) > slop) {
intercept = true;
}
break;
}
case MotionEvent.ACTION_DOWN: {
originalX = ev.getX();
break;
}
}
return (super.onInterceptTouchEvent(ev) || intercept);
}
는 가로 만 왼쪽/오른쪽 스 와이프 및 기타 모든 이벤트에 두어야 : 그래서 그 스크롤 뷰가 차단하고자하는 터치 이벤트를 결정합니다, 그래서
ScrollView
를 서브 클래스와
onInterceptTouchEvent
을 무시했다 어린이보기. 스크롤 뷰 내부의 버튼이 제대로 작동하는 것처럼 보이지만 어쨌든 내 청취자는 호출되지 않습니다. XML에서
내보기는 다음과 같습니다
<com.damluar.mobile.inbox.MyScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
android:id="@+id/detailLayout">
<LinearLayout
android:id="@+id/detailButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:background="@color/default_color">
</LinearLayout>
</LinearLayout>
</com.damluar.mobile.inbox.MyScrollView>
내가 쓴으로는, 내 터치 리스너가 호출되지 않습니다. 그래서 당신의 청취자는 이런 식으로 나아지지 않습니다. – damluar