Android-->实现可滑动删除的Layout

这篇博客介绍了如何在Android开发中实现可滑动删除的Layout,类似于微信和QQ的会话列表功能。作者基于某大神的博文进行改进,解决了事件冲突和bug。文章详细阐述了SwipeLayout的布局设计、代码实现以及如何在Activity中使用SwipeLayout。
摘要由CSDN通过智能技术生成

    做Android开发,经常会碰到仿照IOS实现某种功能的需求。每当碰到这种需求的时候,我其实很抵触的。类似滑动删除的需求更是家常便饭。比如微信、QQ的会话列表都是有滑动删除的功能,Android也有比较成熟的开源项项目SwipeListview来实现列表的滑动删除功能。前不久,碰到一个需求是某个布局带滑动删除的功能。正好以前有读过某大神的博文高仿微信对话列表滑动删除效果,所以本文实现在其基础上加以改进。

  最终要实现效果如下。

    

    大家有兴趣可以先读下高仿微信对话列表滑动删除效果,了解其核心思想。我这边主要是基于该文解决某些事件冲突和bug。

    接着来分析SwipeLayout的具体实现。

    1.SwipeLayout所需布局container_swipelayout.xml

<merge xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/view_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/view_right"
        android:layout_width="120dp"
        android:layout_height="match_parent"
        android:clickable="true" >
    </RelativeLayout>

</merge>
这里我把SwipeLayout的布局分为两个部分,view_content用于加载上面效果图的黄色区域,view_right用于加载红色区域。这样区分的好处是我们可以实现任何你想要的效果了。

接着来看SwipeLayout的代码实现,在代码注释中,已经说明如何解决事件冲突。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值