1、SwipeBackLayout
项目地址:
2、用法
android studio
compile 'me.imid.swipebacklayout.lib:library:1.0.0'
项目实例
package com.example.yiba8.myapplication;import android.os.Bundle;import android.util.DisplayMetrics;import android.view.View;import android.widget.TextView;import me.imid.swipebacklayout.lib.SwipeBackLayout;import me.imid.swipebacklayout.lib.app.SwipeBackActivity;public class BackActivity extends SwipeBackActivity { private TextView back ; private SwipeBackLayout mSwipeBackLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_back); mSwipeBackLayout = getSwipeBackLayout(); int flag1 = SwipeBackLayout.EDGE_LEFT ; //左滑 int flag2 = SwipeBackLayout.EDGE_RIGHT ; //右滑 int flag3 = SwipeBackLayout.EDGE_BOTTOM ; //下滑 int flag4 = SwipeBackLayout.EDGE_ALL ; //全部 //设置滑动模式 mSwipeBackLayout.setEdgeTrackingEnabled(flag4); //自动调用滑动模式 back = (TextView) findViewById( R.id.back ); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { scrollToFinishActivity(); } }); //设置是否可以滑动 mSwipeBackLayout.setEnableGesture(true); //获取屏幕的宽度 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int phoneWidth = dm.widthPixels ; //设置侧滑的区域为屏幕宽度的1/3,如果不设置系统默认为50dip mSwipeBackLayout.setEdgeSize( phoneWidth / 3 ); }}
3、常见的问题
3.1 滑动后背景显示为黑屏
解决方法:在需要侧滑的 Activity 添加一个 Theme
对activity添加theme
4、项目下载