项目地址:https://github.com/kumaxiong/MirrorSwipeBack
- 继承自LinearLayout,左右滑动出现返回动画。
- 默认设置左右两端都能够滑动,可以自行设置。(默认左右两侧)
- 可以自行设置回调事件(默认就是调用当前activity的finish)
- 项目类非常简单就俩类,一个Layout,一个辅助类:MirrorSwipeBack
在build.gradle中引用
implementation 'com.kumaxiong.android:mirror-swipeback-layout:0.1.2'
- 在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。