android 左滑删除

build.gradle中添加依赖

dependencies {
    ···
    //侧滑删除
    implementation 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'
    ···
}

条目视图 最外层添加<com.mcxtzhang.swipemenulib.SwipeMenuLayout><com.mcxtzhang.swipemenulib.SwipeMenuLayout/>标 签

<?xml version="1.0" encoding="utf-8"?>
<com.mcxtzhang.swipemenulib.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_120"
    android:layout_margin="@dimen/dp_15">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/iv_logo"
            android:layout_width="@dimen/dp_50"
            android:layout_height="@dimen/dp_50"
            android:layout_marginLeft="@dimen/dp_20"
            android:layout_marginTop="@dimen/dp_20"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_launcher_background"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tv_education"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/dp_20"
            android:textColor="@color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintRight_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
  <!--> 
    上面是条目正常显示视图,下面是左滑后显示的视图
  <-->
    <Button
        android:id="@+id/btn_delete"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#F40303"
        android:text="删除"
        android:textColor="@android:color/white"/>
</com.mcxtzhang.swipemenulib.SwipeMenuLayout>

至此左滑就可以展示出删除按钮
适配器中设置Button的点击事件就ok了

注意:并不只是列表中才能使用,用的到侧滑的地方都可以用
github:https://github.com/mcxtzhang/SwipeDelMenuLayout

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容