仿IOS边界滑动关闭Activity

Step1:

dependencies {
    compile 'com.cxz:swipeback:1.0.1'
}

Step2:

/**
 * Created by wangx on 2019/12/23.
 * 支持边界滑动关闭手势的BaseActivity
 */
public abstract class BaseSwipeBackActivity extends BaseActivity implements SwipeBackActivityBase {

    private SwipeBackActivityHelper mHelper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHelper = new SwipeBackActivityHelper(this);
        mHelper.onActivityCreate();
        initSwipeBack();
    }

    private void initSwipeBack() {
        setSwipeBackEnable(true);
        mHelper.getSwipeBackLayout().setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        //onPostCreate方法是指onCreate方法彻底执行完毕的回调
        mHelper.onPostCreate();
    }

    @Override
    public SwipeBackLayout getSwipeBackLayout() {
        return mHelper.getSwipeBackLayout();
    }

    @Override
    public void setSwipeBackEnable(boolean enable) {
        mHelper.getSwipeBackLayout().setEnableGesture(enable);
    }

    @Override
    public void scrollToFinishActivity() {
        Utils.convertActivityToTranslucent(this);
        mHelper.getSwipeBackLayout().scrollToFinishActivity();
    }
}

Step3:

使用时直接继承BaseSwipeBackActivity即可,不用考虑Theme之类的东西,很方便!

你可能感兴趣的:(框架,安卓常用框架)