Swipe Back - Free

  • Swipe Back Library, Android Library
  • Description

  • change log

  • faq

  • Comments

  • SwipeBack

    SwipeBack is for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swipe gesture


    SwipeBack is available on maven central
    	compile 'com.hannesdorfmann:swipeback:1.0.0'

    How to use it

    It's not supported yet to build it from xml. You simply have to set it up in you Activities onCreate() method. Instead of Activity.setContentView() call SwipeBack.setContentView().
    public class SwipeBackActivity extends FragmentActivity{
        public void onCreate(Bundle saved){
            // Init the swipe back
            SwipeBack.attach(this, Position.LEFT)
        public void onBackPressed(){

    The code above will use the default setup. R.layout.swipeback_default, the default swipe back layout is already provided by this library as well as DefaultSwipeBackTransformer, R.anim.swipeback_stack_to_front, R.anim.swipeback_stack_to_back, R.anim.swipeback_stack_right_in and R.anim.swipeback_stack_right_out.


    The most important thing is the SwipeBackTransformer. This interface provides an API that will be called from the SwipeBack class. Here is where you implement frame by frame animation while the swipe back view will become open (by users swipe gesture). Additionally you can customize the SwipeBack position, the drag mode (drag content or drag window) and if it should be drawn as overlay or not (Type.BEHIND or Type.OVERLAY).

         * Attaches the SwipeBack to the Activity.
         * @param activity
         *            The activity the swipe back will be attached to.
         * @param type
         *            The {@link SwipeBack.Type} of the drawer.
         * @param position
         *            Where to position the swipe back.
         * @param dragMode
         *            The drag mode of the drawer. Can be either
         *            {@link SwipeBack#DRAG_CONTENT} or
         *            {@link SwipeBack#DRAG_WINDOW}.
         * @return The created SwipeBack instance.
        public static SwipeBack attach(Activity activity, Type type, Position position, int dragMode, SwipeBackTransformer transformer)

    You can also draw a divider between the normal content view and the swipe back view and a overlay that will fade out while opening the swipe back view.

    SwipeBack.attach(this, Position.LEFT)
            .setDividerEnabled(true) // Must be called to enable, setDivider() is not enough
            .setSwipeBackTransformer(new SlideSwipeBackTransformer())


    To distinguish a ViewPager swipe gesture from a SwipeBack swipe gesture you have to setup a OnInterceptMoveEventListener:

    public class ViewPagerActivity extends FragmentActivity {
        private ViewPager mViewPager;
        private int mPagerPosition;
        private int mPagerOffsetPixels;
        public void onCreate(Bundle savedInstanceState) {
            SwipeBack.attach(this, Position.LEFT)
                    new OnInterceptMoveEventListener() {
                        public boolean isViewDraggable(View v, int dx,
                                int x, int y) {
                            if (v == mViewPager) {
                                return !(mPagerPosition == 0 && mPagerOffsetPixels == 0)
                                        || dx < 0;
                            return false;
            mViewPager = (ViewPager) findViewById(R.id.viewPager);
            mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
            mViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener(){
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                    mPagerPosition = position;
                    mPagerOffsetPixels = positionOffsetPixels;
    There is no Features content
  • There is no Related Products
  • There is no Change Log content
  • There is no FAQ