SwipeLayout 仿qq会话列表简单侧滑【删除,修改】

本文介绍了如何使用SwipeLayout在ListView中实现类似QQ会话列表的侧滑删除和编辑功能。SwipeLayout具有良好的兼容性和易用性,解决了手势冲突问题。文章详细讲解了依赖添加、布局配置、适配器和点击事件的处理,以及如何添加自定义的侧滑监听来实现更多功能。

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

前言:

使用SwipeLayout的优点:

  • 1.无论是在RecyclerView,ListView,还是LinearLayout等,只要是ViewGroup用该控件都能实现侧滑。
  • 2.控件的手势滑动冲突已解决,不会出现嵌套到ScrollView等控件出现滑动不流畅的情况。
  • 3.控件使用简单,只需要在xml外套一层该控件就好了,秒接入。
  • 4.点击事件很方便,可根据自己所写布局ID进行设置。

在开始前咱们可以先看看实现出来的效果:

佳姝1:首先,我是使用的ListView所以我只添加了一行依赖,如过使用RecyclerView还需添加它的依赖。

implementation "com.daimajia.swipelayout:library:1.2.0@aar"
implementation 'com.android.support:recyclerview-v7:25.0.1'

 佳姝2:布局,(1)Activity中添加ListView 控件,(2)适配器中添加以下布局。

item_namelist.xml:

<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/R.id.swipelayout"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="vertical"
    tools:context=".ui.activity.MainActivity">

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

        <ImageView
            android:id="@+id/iv_look"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_look_list" />

        <ImageView
            android:id="@+id/iv_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_edit_list" />

        <ImageView
            android:id="@+id/iv_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_delete_list" />

    </LinearLayout>

    <!--以上需添加侧滑后所显示的布局,以下需添加适配器Item所显示内容的布局-->
    
    <LinearLayout
        android:id="@+id/show_content_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shadowbgcolor"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_flie_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingStart="20dp"
                android:text="灯影科技有限公司年会"
                android:textColor="@color/text_color_01"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tv_beacon_states"
                android:layout_widt
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值