일반적으로 DrawerLayout
의 컨텐츠 영역을 누르면 서랍이 닫히고 터치가 소모됩니다. 이를 방지하고 터치 이벤트를 콘텐츠 영역으로 전달할 수있는 방법이 있습니까?DrawerLayout이 컨텐츠 영역의 터치를 처리하지 못하도록합니다.
감사합니다.
일반적으로 DrawerLayout
의 컨텐츠 영역을 누르면 서랍이 닫히고 터치가 소모됩니다. 이를 방지하고 터치 이벤트를 콘텐츠 영역으로 전달할 수있는 방법이 있습니까?DrawerLayout이 컨텐츠 영역의 터치를 처리하지 못하도록합니다.
감사합니다.
guy_m의 답에 영감을 얻어 필자는 제안서를 채택하고 DrawerLayout의 다음 확장을 제안합니다. 다시,이 해결책은 onInterceptTouchEvent()를 오버라이드 (override)하는 것입니다.
최우선 방법의 논리
은 매우 간단하다 : 터치 이벤트가 서랍보기합니다 (DrawerLayout의 슬라이딩 부분) 떨어져 를 발생할 때마다오버 라이딩 된 onInterceptTouchEvent() 메소드의 다음 예제는 드로어보기가 화면 오른쪽에있는 DrawerLayout (android : gravity = "right")에 대한 것입니다. 그러나 표준 왼쪽 배치 서랍보기에서도 작동하도록 코드를 적용하는 방법이 분명해야합니다.
public class CustomDrawerLayout extends DrawerLayout
{
@Override
public boolean onInterceptTouchEvent(MotionEvent event)
{
final View drawerView = getChildAt(1);
final ViewConfiguration config = ViewConfiguration.get(getContext());
// Calculate the area on the right border of the screen on which
// the DrawerLayout should always intercept touch events.
// In case the drawer is closed, we still want the DrawerLayout
// to respond to touch/drag gestures there and reopen the drawer!
final int rightBoundary = getWidth() - 2 * config.getScaledTouchSlop();
// If the drawer is opened and the event happened
// on its surface, or if the event happened on the
// right border of the layout, then we let DrawerLayout
// decide if it wants to intercept (and properly handle)
// the event.
// Otherwise we don't let DrawerLayout to intercept,
// letting its child views handle the event.
return (isDrawerOpen(drawerView) && drawerView.getLeft() <= event.getX()
|| rightBoundary <= event.getX())
&& super.onInterceptTouchEvent(event);
}
...
}
DrawerLayout이 수정되었습니다.
onInterceptTouchEvent(MotionEvent ev)
의 경우 interceptForTap
이 true로 설정되지 않도록해야합니다. 한 가지 방법은 다음 조건을 제거하는 것입니다.
if (mScrimOpacity > 0 &&
isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
interceptForTap = true;
}
이렇게하면 넘어 질 수 있습니다.
는LOCK_MODE_LOCKED_OPEN
에 서랍 잠금 모드를 설정할 수 있습니다 닫지 서랍을합니다.
이것이 문제를 해결하는 이유에 대한 설명을 해 줄 수 있습니까? – Rob
죄송합니다. 이전에 설명을 입력했지만 어떻게 든 게시에 분실했습니다. 나는 대답을 편집 할 것이다. –
이것은 아마 내 해킹보다 나은 해결책입니다. – paul