Skip to content

Code4Bug/MirrorSwipeBack

 
 

Repository files navigation

项目地址:https://github.com/kumaxiong/MirrorSwipeBack

MirrorSwipeBack

  1. 继承自LinearLayout,左右滑动出现返回动画。
  2. 默认设置左右两端都能够滑动,可以自行设置。(默认左右两侧)
  3. 可以自行设置回调事件(默认就是调用当前activity的finish)
  4. 项目类非常简单就俩类,一个Layout,一个辅助类:MirrorSwipeBack

ezgif-1-7a33c98bc2.gif

Download

在build.gradle中引用

 implementation 'com.kumaxiong.android:mirror-swipeback-layout:0.1.2'

使用

  1. 在layout文件夹下建立:layout_swipe_back.xml
<com.kumaxiong.MirrorSwipeBackLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>
xml 中直接设置左右滑动是否开启

<com.kumaxiong.MirrorSwipeBackLayout
  android:id="@+id/mirror_swipe"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:mirror_attr= "http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  mirror_attr:left_swipe="true"
  mirror_attr:right_swipe="false"
  />

2.在需要使用的activity中的onCreate方法中加入:

public class MainActivity extends AppCompatActivity {

    MirrorSwipeBackLayout mMirrorSwipeBackLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mMirrorSwipeBackLayout = MirrorSwipeBack.attach(this, R.layout.layout_swipe_back);
        mMirrorSwipeBackLayout.setLeftSwipeEnable(true);
        mMirrorSwipeBackLayout.setRightSwipeEnable(true);
        mMirrorSwipeBackLayout.setSwipeBackListener(new MirrorSwipeBackLayout.OnSwipeBackListener() {
            @Override
            public void completeSwipeBack() {
                // 你自己的逻辑
                Toast.makeText(MainActivity.this, "滑动返回 completeSwipeBack", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

项目地址

如果觉得对你有帮助,欢迎star 。 使用过程中有问题,欢迎issue。

https://github.com/kumaxiong/MirrorSwipeBack

About

仿MIUI滑动返回

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%