Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.NaikSoftware:accordion-swipe-layout:0.5.19'
}
dependencies {
implementation("com.github.NaikSoftware:accordion-swipe-layout:0.5.19")
}
<dependency>
<groupId>com.github.NaikSoftware</groupId>
<artifactId>accordion-swipe-layout</artifactId>
<version>0.5.19</version>
</dependency>
libraryDependencies += "com.github.NaikSoftware" % "accordion-swipe-layout" % "0.5.19"
:dependencies [[com.github.NaikSoftware/accordion-swipe-layout "0.5.19"]]
Easy accordion swipe layout for Android.
<img src="http://i.giphy.com/l3vR2q08LFkNHDgg8.gif" width="300">Very easy to use
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.3.0'
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>
Create array.xml in your values folder Add custom integer arrays for drawables and swipable item backgrounds
<?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>
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:layout="@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" />
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
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;
}
}
}
});
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