将SlidingPaneLayout的触摸事件限制在屏幕的最左边缘

时间:2013-08-30 12:35:46

标签: java android slidingpanelayout

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

1 个答案:

答案 0 :(得分: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);
}
}