Easy, flexible and powerful Swipe Layout for Android

Overview

SwipeRevealLayout

A layout that you can swipe/slide to show another layout.

Demo

Overview

Demo all

Drag mode

Drag mode normal:
Demo normal

Drag mode same_level:
Demo same

Features

  • Flexible, easy to use with RecyclerView, ListView or any view that requires view binding.
  • Four drag edges (left, right, top, bottom).
  • Two drag modes:
    • Normal (the secondary view is underneath the main view).
    • Same level (the secondary view sticks to the edge of the main view).
  • Able to open one row at a time.
  • Minimum api level 9.

Usage

Dependencies

dependencies {
    compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
}

Layout file

<com.chauthai.swipereveallayout.SwipeRevealLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mode="same_level"
        app:dragEdge="left">

        <!-- Your secondary layout here -->
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <!-- Your main layout here -->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
            
</com.chauthai.swipereveallayout.SwipeRevealLayout>

app:mode can be normal or same_level

app:dragEdge can be left, right, top or bottom

Use with RecyclerView, ListView, GridView...

In your Adapter class:
public class Adapter extends RecyclerView.Adapter {
  // This object helps you save/restore the open/close state of each view
  private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();
  
  public Adapter() {
    // uncomment the line below if you want to open only one row at a time
    // viewBinderHelper.setOpenOnlyOne(true);
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    // get your data object first.
    YourDataObject dataObject = mDataSet.get(position); 
    
    // Save/restore the open/close state.
    // You need to provide a String id which uniquely defines the data object.
    viewBinderHelper.bind(holder.swipeRevealLayout, dataObject.getId()); 

    // do your regular binding stuff here
  }
}
Optional, to restore/save the open/close state when the device's orientation is changed:
Adapter class:
public class YourAdapter extends RecyclerView.Adapter {
  ...

  public void saveStates(Bundle outState) {
      viewBinderHelper.saveStates(outState);
  }

  public void restoreStates(Bundle inState) {
      viewBinderHelper.restoreStates(inState);
  }  
}
Activity class:
public class YourActivity extends Activity {
  ...
  
  @Override
  protected void onSaveInstanceState(Bundle outState) {
      super.onSaveInstanceState(outState);
      if (adapter != null) {
          adapter.saveStates(outState);
      }
  }

  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);
      if (adapter != null) {
          adapter.restoreStates(savedInstanceState);
      }
  }
}

Useful Methods/Attributes

app:minDistRequestDisallowParent: The minimum distance (in px or dp) to the closest drag edge that the SwipeRevealLayout will disallow the parent to intercept touch event. It basically means the minimum distance to swipe until a RecyclerView (or something similar) cannot be scrolled.

setSwipeListener(SwipeListener swipeListener): set the listener for the layout. You can use the full interface SwipeListener or a simplified listener class SimpleSwipeListener

open(boolean animation), close(boolean animation): open/close the layout. If animation is set to false, the listener will not be called.

isOpened(), isClosed(): check if the layout is fully opened or closed.

setMinFlingVelocity(int velocity): set the minimum fling velocity (dp/sec) to cause the layout to open/close.

setDragEdge(int edge): Change the edge where the layout can be dragged from.

setLockDrag(boolean lock): If set to true, the user cannot drag/swipe the layout.

viewBinderHelper.lockSwipe(String... id), viewBinderHelper.unlockSwipe(String... id): Lock/unlock layouts which are binded to the binderHelper.

viewBinderHelper.setOpenOnlyOne(boolean openOnlyOne): If openOnlyOne is set to true, you can only open one row at a time.

viewBinderHelper.openLayout(String id): Open a layout. id is the id of the data object which is bind to the layout.

viewBinderHelper.closeLayout(String id): Close a layout. id is the id of the data object which is bind to the layout.

License

 The MIT License (MIT)

 Copyright (c) 2016 Chau Thai

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
Comments
  • onItemClick in ListView not working...

    onItemClick in ListView not working...

    regarding on #6 , still i cannot make it work pls. help... specially the last part that you mentioned... "use adapter.setOnItemClickListener() before attaching it to the listview"... sorry i just new on android development.. thanks :)

    question 
    opened by zhockz 10
  • Last item of adapter XML not filling parent

    Last item of adapter XML not filling parent

    Hello, i was testing your library to use it on an app and i found a weird bug. this is my swipe layout test xml : <!-- Your secondary layout here --> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="20dp"> <Button android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="EDIT"/> <Button android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="DELETE"/> </LinearLayout> using RecyclerView.Adapter's typical implementation (https://developer.android.com/training/material/lists-cards.html) , and following your readme guide, on the last item of the adapter's dataset, the buttons show small (wrapped around the text) and don't match or fill the parent ( i've tried both match_parent and fill_parent) , it looks like they're defaulting to wrap_content.

    the rest of the interface works correctly, and the rest of items show fine, it's just the last two buttons.

    bug 
    opened by tryadelion 10
  • How to Handle Click Events on Delete Button?

    How to Handle Click Events on Delete Button?

    I'm using Recycler view and managed to show the delete button. Now how can I handle the delete button. I need to get the unique id of clicked delete button. Is it possible?

    question 
    opened by amarilindra 8
  • Swipe one view at one time

    Swipe one view at one time

    Hello

    I have checked your library, it is cool library. Your library allow me to swipe multiple list items to delete. But I want to open one row at one time. e.g. I have opened my listview's item no. 2, now if I open other item then the previous row should be closed. Please let me know. How can I do it with your library. Thanks

    resolved 
    opened by cresttechnosoft 7
  • How can i set drag sensitivity for swipe layout

    How can i set drag sensitivity for swipe layout

    How can i set drag sensitivity for swipe layout ? In the some devices (as Sony Xperia Z4), too difficult to click children in swipe layout.

    I did try this: mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback); ==> mDragHelper = ViewDragHelper.create(this, 0.1f, mDragHelperCallback); But it still too sensitivity, so difficult to click to children view.

    Thanks in advanced.

    opened by tanakasama 5
  • Fixed issue with sensitive swipe item

    Fixed issue with sensitive swipe item

    Before, when click on item in recycler view, click event fires not immediately, 'cause reveal layout was very sensitive and he has try to swipe. Click event fires from 3-rd or 5-th time. Now this problem is fixed

    opened by DenisMakovskyi 4
  • How to set OnClickListener for whole SwipeRevealLayout ?

    How to set OnClickListener for whole SwipeRevealLayout ?

    Hi, I wanna set a clickListener for the swipeRevealLayout, and when the swipeRevealLayout is closed and click it, call the clickListener. Any suggestions ? :)

    question 
    opened by JoeShiguang 4
  • ListView OnItemClickListener not working

    ListView OnItemClickListener not working

    if I set the

     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                      click();
                }
            });
    

    the event is never fired. I tried to put as many items in my row not clickable or focusable. Is that something that can happen with this library or should I look somewhere else?

    opened by albert0m 4
  • rows don't adapt on rotation

    rows don't adapt on rotation

    how can I have the rows to readapt to the new width on rotation? I would like to avoid to handle the rotation event and redraw the whole list. Is there a way?

    thank you

    opened by albert0m 3
  • conflict with other libraries?

    conflict with other libraries?

    Hello.. I think there is conflict with google service and support libraries, cause when I just add dependecy of swipereveallayout and ran project it stopped with this error: "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included."

    support version 23.3.0 play-services 8.4.0 what is the solustion?

    opened by basmasrour 3
  • setOpenOnlyOne does not work

    setOpenOnlyOne does not work

    I am using version 1.4.0 on Android 6.0.1 and the setOpenOnlyOne option doesn't seem to work.

    I use Gradle to get the library as follows:

    compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.0'

    Then in my view holder I create the binderhelper and set the setOpenOnlyOne option as follows:

    private final ViewBinderHelper viewBinderHelper;
    viewBinderHelper = new ViewBinderHelper();
    viewBinderHelper.setOpenOnlyOne(true);
    

    I am using a RecyclerView and I can still slide all of the views open.

    However

    opened by DonalRafferty 2
  • Is this repo actively maintained?

    Is this repo actively maintained?

    There where no releases since 2016 and no pull requests are merged since 2016. So I guess this repo can be considered as dead?

    I'm thinking about forking it, add improvements from pull requests/issue-comments and publish it to Maven. But I do not want/need to do this if the maintainer is still planning to continue working on this library.

    opened by niklasdahlheimer 2
  • When Swipe item, another item in list automatically swipe #18

    When Swipe item, another item in list automatically swipe #18

    Check this video

    https://drive.google.com/file/d/1ix1Yxdh-EcUAVQ0rhrMNdcLU6BBgSTb1/view

    Any solution for this?

    Also, I want to implement a favorite option I implement it and when I add one item in the favorite list (favorite item's image drawable is changed) another item's image drawable is automatically changed

    opened by kishorramani 3
  • Incorrect attribute set for dragEdge

    Incorrect attribute set for dragEdge

    dragEdge in attrs.xml https://github.com/chthai64/SwipeRevealLayout/blob/master/swipe-reveal-layout/src/main/res/values/attrs.xml#L6-L9

    is made as a bitmask, which is not true based on quick code review.

    Change it please to enum, otherwise you can do in layout following, which doesn't work at all...

    app:dragEdge="left|right"
    
    opened by jiribruchanov-ubs 0
  • ChildView height is not Matching the parent view  when we dynamically change parent view items visibility

    ChildView height is not Matching the parent view when we dynamically change parent view items visibility

    I have a recycler view in which I have parent view and child view two layout , in which my parent view has some three text and one read more button which will help to hide and show text dynamically.

    After clicking on button when height of parent view changes, child view height still remain same to the initial state.

    How can I increase the child view height dynamically with change in the height of parent view ?

    Any help in this will be really appreciable . Thanks

    opened by rjtkumar007 1
Releases(1.4.0)
Owner
Chau Thai
Chau Thai
ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way

ConstraintLayout is a layout manager for Android which allows you to position and size widgets in a flexible way. It's available for both the Android view system and Jetpack Compose.

Android Jetpack 970 Jan 6, 2023
GoolgePlusLayout is a custom layout that plays animation on the children views while scrolling as the layout in the Google Plus (android) main page

Google Plus Layout Google Plus Layout is a custom layout that support playing animation on child view(s) in a serialize manner like the the main

Ahmed Nammari 224 Nov 25, 2022
Responsive Layout Gird Configuration using Compose. An adaptive layout

ResponsiveGrid Responsive Grid is most followed layout system by the designer as it adapts to screen size and orientation, ensuring consistency across

null 4 Apr 12, 2022
null 2.4k Dec 30, 2022
An Android library that help you to build app with swipe back gesture.

SwipeBackLayout An Android library that help you to build app with swipe back gesture. Demo Apk GooglePlay Requirement The latest android-support-v4.j

ike_w0ng 6.1k Dec 29, 2022
An Android library that help you to build app with swipe back gesture.

SwipeBackLayout An Android library that help you to build app with swipe back gesture. Demo Apk GooglePlay Requirement The latest android-support-v4.j

ike_w0ng 6.1k Jan 3, 2023
swipe display drawer with flowing & bouncing effects.

FlowingDrawer swipe right to display drawer with flowing effects. Download Include the following dependency in your build.gradle file. Gradle: rep

mxn 2.6k Jan 3, 2023
FixedHeaderTableLayout is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells with scrolling and zooming features. FixedHeaderTableLayout is similar in construction and use as to Android's TableLayout

FixedHeaderTableLayout is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells with scrolling and zooming features. FixedHeaderTableLayout is similar in construction and use as to Android's TableLayout

null 33 Dec 8, 2022
BlurView - A very fast and dynamic blur layout for Android

BlurView - A very fast and dynamic blur layout for Android

null 16 Jul 11, 2022
A layout that hide the header when the body is scrolled down and reveal it when the header is scrolled up

AndroidAutoHideHeader A layout that hide the header when the body is scrolled down and reveal it when the header is scrolled up Demo Import it ! In yo

Vadim Caen 48 Apr 22, 2022
A Playground repository to showcase UI's and transitions built using Motion Layout.

A collection of UI's built to showcase the capabilities of Motion Layout and Constraint Layout 2.0/2.1

Saurabh 163 Dec 22, 2022
An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu

ResideLayout An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu. Can be used on Android 1.6(I haven't try it.)

Yang Hui 392 Oct 12, 2022
A very simple arc layout library for Android

ArcLayout A very simple arc layout library for Android. Try out the sample application on the Play Store. Usage (For a working implementation of this

ogaclejapan 1.4k Dec 26, 2022
Android layout that simulates physics using JBox2D

PhysicsLayout Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall! See it in action with the sam

John Carlson 689 Dec 29, 2022
An Android demo of a foldable layout implementation. Engineered by Vincent Brison.

Foldable Layout This code is a showcase of a foldable animation I created for Worldline. The code is fully written with java APIs from the Android SDK

Worldline 599 Dec 23, 2022
A 3D Layout for Android,When you use it warp other view,it can became a 3D view,一秒让你的view拥有3D效果!

ThreeDLayout A 3D Layout,When you use it warp other view,it can became a 3D view 中文文档 preview USAGE 1.compile library allprojects { repositories {

androidwing 490 Oct 27, 2022
It's an Android library that allows you to use Layout as RadioButton or CheckBox.

Android - CompoundLayout It's an Android library that allows you to use Layout as RadioButton or CheckBox. The librarie is Android 14+ compatible. Gra

null 483 Nov 25, 2022
A pull to refresh layout for android, the RecyclerRefreshLayout is based on the SwipeRefreshLayout. support all the views, highly customizable, code simplicity, etc. really a practical RefreshLayout!

RecyclerRefreshLayout English | 中文版 RecyclerRefreshLayout based on the {@link android.support.v4.widget.SwipeRefreshLayout} The RecyclerRefreshLayout

dinus_developer 1.7k Nov 10, 2022