Accordion Swipe Layout for Android

Overview

Android Accordion Swipe Layout

Inspired by iOS Mail app

Easy accordion swipe layout for Android.

Very easy to use

Step 1

Gradle

Add to root project gradle

allprojects {
    repositories {
        maven {
            url "https://jitpack.io"
        }
    }
}

Add dependency to app gradle

compile 'com.github.alexandrius:accordion-swipe-layout:0.5.0'

Step 2

Create main layout for your swipable item.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#a9a9a9"
        android:gravity="center"
        android:text="This is sample" />
</LinearLayout>

Step 3

Create array.xml in your values folder Add custom integer arrays for drawables and swipable item backgrounds

Example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer-array name="rightColors">
        <item>@color/color1</item>
        <item>@color/color2</item>
        <item>@color/color3</item>
    </integer-array>

    <integer-array name="leftColors">
        <item>@color/color4</item>
        <item>@color/color5</item>
        <item>@color/color6</item>
    </integer-array>

    <integer-array name="rightDrawables">
        <item>@mipmap/ic_reload</item>
        <item>@mipmap/ic_settings</item>
        <item>@mipmap/ic_trash</item>
    </integer-array>

    <integer-array name="leftDrawables">
        <item>@mipmap/ic_reload</item>
    </integer-array>

    <string-array name="rightTexts">
        <item>@string/reload</item>
        <item>@string/settings</item>
        <item>@string/trash</item>
    </string-array>

</resources>

Step 4

Add SwipeLayout into your layout

<com.alexandrius.accordionswipelayout.library.SwipeLayout
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    app:iconSize="@dimen/icon_size"
    app:foregroundLayout="@layout/sample_item"
    app:leftItemColors="@array/leftColors"
    app:leftItemIcons="@array/leftDrawables"
    app:rightItemColors="@array/rightColors"
    app:rightItemIcons="@array/rightDrawables"
    app:swipeItemWidth="@dimen/swipe_item_width" />

Available attrs:

  1. iconSize
  2. foregroundLayout - pass id of previously created layout
  3. leftItemColors
  4. leftItemIcons
  5. leftTextColors
  6. rightTextColors
  7. rightItemColors
  8. rightItemIcons
  9. swipeItemWidth
  10. leftStrings
  11. rightStrings
  12. textSize
  13. textTopMargin
  14. customFont
  15. canFullSwipeFromLeft
  16. canFullSwipeFromRight
  17. autoHideSwipe - automatically collapse item on scroll
  18. onlyOneSwipe - automatically collapse other item if expanded

canFullSwipeFromLeft - set swipe to maximum width (like in gif preview) from left. Executes listener for first item

canFullSwipeFromRight - set swipe to maximum width (like in gif preview) from right. Executes listener for last item

Step 5

Add click listener to swipe items

SwipeLayout swipeLayout = (SwipeLayout) findViewById(R.id.swipe_layout);
swipeLayout.setOnSwipeItemClickListener(new SwipeLayout.OnSwipeItemClickListener() {
    @Override
    public void onSwipeItemClick(boolean left, int index) {
        if (left) {
            switch (index) {
                case 0:
                    break;
            }
        } else {
            switch (index) {
                case 0:
                    break;
            }
        }
    }
});

Expand and collapse programmatically

ITEM_STATE_LEFT_EXPAND
ITEM_STATE_RIGHT_EXPAND
ITEM_STATE_COLLAPSED

swipeLayout.setItemState(SwipeLayout.ITEM_STATE_LEFT_EXPAND, animated);

That's pretty much it. Thanks

Comments
  • Programatically change the icons

    Programatically change the icons

    Hey man, really cool library, one of the very few that actually work. I have one question tho. How can I change the icons/colors in the runtime? Changing them in the recycler adapter did nothing.

    Thank you in advance!

    opened by ionutboanta 4
  • Attribute

    Attribute "layout" has already been defined

    The attribute "layout" clashes with the attribute "layout" of the android support library. Could it be renamed to something more specific like foregroundLayout, baseItemLayout...

    opened by ghost 3
  • License

    License

    Hi, I see that this library is available in the maven repository under Apache License. Can the source code here also be used according to the Apache License? Thanks!

    opened by David-Strauss 2
  • Support for inner child in SwipeLayout

    Support for inner child in SwipeLayout

    <?xml version="1.0" encoding="utf-8"?>
    <com.alexandrius.accordionswipelayout.library.SwipeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        app:canFullSwipeFromRight="true"
        app:iconSize="@dimen/icon_size"
        app:leftItemColors="@array/leftColors"
        app:leftItemIcons="@array/leftDrawables"
        app:rightItemColors="@array/rightColors"
        app:rightItemIcons="@array/rightDrawables"
        app:rightStrings="@array/rightTexts"
        app:rightTextColors="@array/rightTextColors"
        app:swipeItemWidth="@dimen/swipe_item_width"
        app:textSize="@dimen/text_size">
    
        <include layout="@layout/sample_item"/>
    
    </com.alexandrius.accordionswipelayout.library.SwipeLayout>
    

    First child used as item view if no app:layout attribute found.

    opened by NaikSoftware 2
  • How to set left and right drawables programmatically?

    How to set left and right drawables programmatically?

    Hi! I know that there are two methods for this purpose like setRightIcons(int[] res) and setLeftIcons(int[] res), but it seems to me they doesn't work properly. I tried to use them in OnBindViewHolder(ViewHolder holder, int position), but they didn't work. How can I set drawables programmatically?

    opened by Menefrego 0
  • Is this swipe Layout can be use in other layout?

    Is this swipe Layout can be use in other layout?

    Hi, Thanks for nice work.

    I used swipelayout in LinearLayout, and it not at all visible in screen.

    Is this swipe Layout can be use in other layout?

    Please let me know on it.

    Thank you.

    opened by praveenb 1
  • Overlapping Menu Items

    Overlapping Menu Items

    Hi!

    My problem is, that I want to have a left-swipe and a right-swipe menu. In each menu there are 3 different items.

    When I swipe from right to left, all elements are shown beside each other like I want it to be. When I swipe from left to right, the items are overlapping or just two items are showing at the same time (dependend how hard I swipe).

    When I exchange the array values, the same behaviour is happening, so it is not dependent on the content of the items, but the direction of the swipe.

    I set the properties: app:canFullSwipeFromLeft="false" app:canFullSwipeFromRight="false"

    Does anyone have an idea, why that is? Thank you.

    <?xml version="1.0" encoding="utf-8"?> <com.alexandrius.accordionswipelayout.library.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/xxx" android:layout_width="match_parent" android:layout_height="wrap_content" app:mainItemLayout="@layout/item_foreground" app:leftItemColors="@array/swipe_left_colors" app:leftItemIcons="@array/swipe_left_drawables" app:leftStrings="@array/swipe_left_strings" app:rightItemColors="@array/swipe_right_colors" app:rightItemIcons="@array/swipe_right_drawables" app:rightStrings="@array/swipe_right_strings" app:swipeItemWidth="80dp" app:iconSize="40dp" app:canFullSwipeFromLeft="false" app:canFullSwipeFromRight="false" />

    opened by daMatz 5
  • Swipe buttons without icons

    Swipe buttons without icons

    Hello,

    Can I make buttons without icons? Now I must set drawables, set iconSize to 0dp and textTopMargin to 0dp, right? It would be great if I can just not to set drawables in that case.

    opened by crush3r 1
  • Add swipe listeners

    Add swipe listeners

    Hello,

    Thank you for great library, please don't throw this project. I just want to ask you about adding ability to listen of changing swipe states - onExpandRight listener or something like that.

    opened by crush3r 3
Releases(0.5.2)
Owner
Alexander Pataridze
Wannabe creative person
Alexander Pataridze
SwipeBack 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 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 swi

Hannes Dorfmann 697 Dec 14, 2022
Android Library to implement simple touch/tap/swipe gestures

SimpleFingerGestures An android library to implement simple 1 or 2 finger gestures easily Example Library The library is inside the libSFG folder Samp

Arnav Gupta 315 Dec 21, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
Android swipe-to-dismiss mini-library and sample code

Android Swipe-to-Dismiss Sample Code Sample code that shows how to make ListView or other views support the swipe-to-dismiss Android UI pattern. See t

Roman Nurik 1.3k Dec 29, 2022
A swipe button for Android with a circular progress bar for async operations

ProSwipeButton A swipe button for Android with a circular progress bar for async operations Gradle dependencies { ... compile 'in.shadowfax:pr

Shadowfax Technologies 340 Nov 13, 2022
Android jetpack compose swipe library

Swiper for Android Jetpack Compose Android Jetpack Compose swipe library. Downlo

null 32 Dec 10, 2022
A player/ recorder visualizer with the swipe to seek functionality.

iiVisu A player/ recorder visualizer with the swipe to seek functionality. Demo Setup Step 1. Add the JitPack repository to your build file Add it in

Iman Irandoost 126 Nov 25, 2022
A simple implementation of swipe card like StreetView

A simple implementation of swipe card like StreetView!! DONATIONS This project needs you! If you would like to support this project's further developm

Michele Lacorte 831 Jan 4, 2023
Card with swipe options in Jetpack Compose

SwipeableActionCard Card with swipe options in Jetpack Compose Tutorial: Click Here Import SwipeableActionCard library Add this in project level build

Harsh Mahajan 1 Nov 23, 2021
[] A simple way to "badge" any given Android view at runtime without having to cater for it in layout

Android ViewBadger A simple way to "badge" any given Android view at runtime without having to cater for it in layout. Note: If your aim is to replica

Jeff Gilfelt 3k Nov 28, 2022
Shadow layout, shadow view for android.

ShadowViewHelper Shadow layout, shadow view for android. How to use: It's very simple to use. Gradle(Check newest version): compile 'com.github.wangji

WangJie 777 Dec 30, 2022
FogView is a android library that can show fog on any layout and the fog removes when user rubs it.

Fog View Android Library Min SDK 8 (Android 2.2–2.2.3 Froyo) Screnshots How to use If you want use this library, you can download project and import i

Chetan Kaushik 631 Dec 31, 2022
JetCompose - Blur Effect in Android 12 with motion layout carousel

JetCompose Blur Effect in Android 12 with motion layout carousel

Vikas Singh 4 Jul 27, 2022
This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.

StickyGridHeaders Replacement project at SuperSLiM This repository is abandoned and will no longer see any development or support. The replacement Sup

Tonic Artos 1.5k Nov 15, 2022
The CustomCalendarView provides an easy and customizable calendar to create a Calendar. It dispaly the days of a month in a grid layout and allows to navigate between months

Custom-Calendar-View To use the CustomCalendarView in your application, you first need to add the library to your application. You can do this by eith

Nilanchala Panigrahy 113 Nov 29, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

Muthuramakrishnan Viswanathan 1.2k Dec 30, 2022