SwipeLayout实现滑动删除

本文介绍了如何利用SwipeLayout在Android应用中实现滑动删除的效果,类似iOS系统的微信对话框删除功能。通过引入AndroidSwipeLayout库,可以轻松创建侧滑删除和侧滑菜单。文中提到了配置步骤,包括在模块中添加依赖,使用RecyclerView展示数据,以及创建适配器布局。

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

SwipeLayout实现滑动删除

SwipeLayout

我们可以用过这个实现向ios系统上类似于微信上删除对话框的功能,AndroidSwipeLayout(https://github.com/daimajia/AndroidSwipeLayout),顾名思义,Android平台上的滑动布局,是一个可以让我们很方便使用滑动的库,典型的应用就是侧滑删除与侧滑菜单。在android的开发中运用的场景也是很多。如图所示的效果。
在这里插入图片描述
1、配置:
在模块中添加引用:

 compile "com.daimajia.swipelayout:library:1.2.0@aar"
    compile 'com.android.support:recyclerview-v7:23.2.1'```

2、xml布局文件配置:

主布局中添加了一个RecyclerView来显示数据


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.androidswipelayoutdemo.MainActivity">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="文本显示"
/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/tv"
android:id="@+id/mRecycleView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

然后在创建一个xml文件是适配器的布局也是swipelayout的布局

<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/swipe_layout"
    android:layout_height="wrap_content">
    <LinearLayout
        android:background="#66ddff00"
        android:id="@+id/bottom_wrapper"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值