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.
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a9a9a9"
android:gravity="center"
android:text="This is sample" />
Step 3
Create array.xml in your values folder Add custom integer arrays for drawables and swipable item backgrounds
Example:
@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
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:
iconSize
foregroundLayout - pass id of previously created layout
leftItemColors
leftItemIcons
leftTextColors
rightTextColors
rightItemColors
rightItemIcons
swipeItemWidth
leftStrings
rightStrings
textSize
textTopMargin
customFont
canFullSwipeFromLeft
canFullSwipeFromRight
autoHideSwipe - automatically collapse item on scroll
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