手风琴控件android,accordion-swipe-layout:Android手风琴滑动布局

本文介绍了一种在Android中实现类似iOS Mail应用的滑动布局方法。通过使用AccordionSwipeLayout库,开发者可以轻松地为应用添加左右滑动展开的功能。文章详细介绍了库的安装步骤、创建滑动项布局的方法、配置滑动属性以及添加点击监听器的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android Accordion Swipe Layout

Inspired by iOS Mail app

Easy accordion swipe layout for Android.

a53a468a64a3cbe94c5710dcccccd713.gif

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值