[重写开源框架源码]SwipeBackLayout实现全屏滑动

在日常开发中,导入开源框架有时候不能完成项目的需要,没办法,这时候只好去重写它的部分原来,以达到自己想要的需求。

目录:

    • 目录
    • SwipeBackLayout开源框架
      • 在SwipeBackLayoutjava中最后那里增加这部分代码
      • 在ViewDragHeperjava中最后那里这个去修改源码
      • 然后再activity中调用的时候只需要这样

SwipeBackLayout开源框架

它可以实现app的侧滑返回,类似他趣中的右滑返回上一个activity。该项目地址:https://github.com/ikew0ng/SwipeBackLayout

但是它不能实现全屏侧滑,可能是笔者自己水碧,尝试了它提供的各种办法都不能实现。于是,索性修改它源码,其实也就增加几句话而已。

① 在SwipeBackLayout.java中,最后那里增加这部分代码

    public static final int FULL_SCREEN_LEFT = ViewDragHelper.EDGE_LEFT;
    public static final int FULL_SCREEN_TOP = ViewDragHelper.EDGE_TOP;
    public static final int FULL_SCREEN_RIGHT = ViewDragHelper.EDGE_RIGHT;
    public static final int FULL_SCREEN_BOTTOM = ViewDragHelper.EDGE_BOTTOM;
    public static final int ORIGINAL = 0X31;

    public void setSwipeMode(int mode) {
        if (mode == SwipeBackLayout.ORIGINAL) {
            mDragHelper.setTouchedFullScreen(false, 0);
        } else {
            mDragHelper.setTouchedFullScreen(true, mode);
        }
    }

② 在ViewDragHeper.java中,最后那里这个去修改源码

    private int getEdgeTouched(int x, int y) {
        int result = 0;

        if (touch_flag) {
            result = flag;
        } else {
            if (x < mParentView.getLeft() + mEdgeSize)
                result = EDGE_LEFT;
            if (y < mParentView.getTop() + mEdgeSize)
                result = EDGE_TOP;
            if (x > mParentView.getRight() - mEdgeSize)
                result = EDGE_RIGHT;
            if (y > mParentView.getBottom() - mEdgeSize)
                result = EDGE_BOTTOM;
        }
        return result;
    }

    private boolean touch_flag;
    private int flag;

    public void setTouchedFullScreen(boolean touch_flag,int flag) {
        this.touch_flag = touch_flag;
        this.flag = flag;
    }

③然后再activity中调用的时候只需要这样

        getSwipeBackLayout().setSwipeMode(SwipeBackLayout.FULL_SCREEN_LEFT);
        getSwipeBackLayout().setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);

在原来的句子前面增加一句就可以全屏滑动了:

getSwipeBackLayout().setSwipeMode(SwipeBackLayout.FULL_SCREEN_LEFT);

相应的如果你是左滑而不是右滑,只需这样:

getSwipeBackLayout().setSwipeMode(SwipeBackLayout.FULL_SCREEN_RIGHT);
getSwipeBackLayout().setSwipeMode(SwipeBackLayout.EDGE_RIGHT);

如果你想通过代码动态改变滑动方式,调用以下:

getSwipeBackLayout().setSwipeMode(SwipeBackLayout.ORIGINAL);

你可能感兴趣的:(APP,swipeback,全屏侧滑返回,全屏侧滑)