1

是否可以将 SlidingPaneLayout 的触摸事件限制在 DrawerLayout 中屏幕链接的最左边缘?

4

1 回答 1

0

是的,但是您想创建自己的 SlidingPaneLayout 实现并覆盖 onTouchEvent(MotionEvent ev) 方法,如下所示

public class SlidingPaneLayoutExtended extends SlidingPaneLayout {

public static final int DEFAULT_DRAGGING_START_X = -1;
public static final int SLIDE_FROM_LEFT_EDGE = 0;

private int startDraggingX = DEFAULT_DRAGGING_START_X;

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


public int getStartDraggingX() {
    return startDraggingX;
}

public void setStartDraggingX(int startX) {
    this.startDraggingX = startX;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (startDraggingX > DEFAULT_DRAGGING_START_X) {
        if ((startDraggingX == SLIDE_FROM_LEFT_EDGE && ev.getAction() == )
                || ev.getX() <= DEFAULT_DRAGGING_START_X) {
            return super.onTouchEvent(ev);
        } else {
            return false;
        }
    }

    return super.onTouchEvent(ev);
}
}
于 2013-10-10T09:55:12.740 回答