1、SwipeBackLayout

项目地址:https://github.com/ikew0ng/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 滑动后背景显示为黑屏

       SwipeBackActivity 的使用-LMLPHP

解决方法:在需要侧滑的 Activity 添加一个 Theme

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
    <style name="AppBackTheme"  parent="@style/AppTheme">
<item name="android:windowIsTranslucent">true</item>
</style>

对activity添加theme

       <!--  侧滑返回  -->
<activity
android:theme="@style/AppBackTheme"
android:name=".BackActivity">
</activity>

4、项目下载

http://download.csdn.net/detail/yanzi2015/9403931

04-25 12:44