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

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

目录:

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);
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值