Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/alexandrius/accordion-swipe-layout

Accordion Swipe Layout for Android
https://github.com/alexandrius/accordion-swipe-layout

Last synced: 1 day ago
JSON representation

Accordion Swipe Layout for Android

Lists

README

        

# 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
```groovy
allprojects {
repositories {
maven {
url "https://jitpack.io"
}
}
}
```

Add dependency to app gradle
```groovy
compile 'com.github.alexandrius:accordion-swipe-layout:0.5.0'
```

## Step 2
Create main layout for your swipable item.

```xml

```

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

### Example:
```xml


@color/color1
@color/color2
@color/color3


@color/color4
@color/color5
@color/color6


@mipmap/ic_reload
@mipmap/ic_settings
@mipmap/ic_trash


@mipmap/ic_reload


@string/reload
@string/settings
@string/trash

```

## Step 4
Add SwipeLayout into your layout

```xml

```

### 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
```java
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
```java
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