滑动删除以及左滑右滑

1.第一步导入依赖

 api 'com.billy.android:smart-swipe:1.0.8'

2.布局

就简易版的解一个串

此处省略

建一个xml文件
这里面是滑动后的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp">
    <TextView
        android:id="@+id/tv_delete"
        android:textSize="20dp"
        android:gravity="center"
        android:textColor="#fff"
        android:background="#F44336"
        android:text="删除"
        android:layout_width="80dp"
        android:layout_height="match_parent">
    </TextView>
    <TextView
        android:textSize="20dp"
        android:gravity="center"
        android:textColor="#fff"
        android:background="#EFC4C1"
        android:text="收藏"
        android:layout_width="80dp"
        android:layout_height="match_parent">
    </TextView>
</LinearLayout>

2.注意事项:

适配器里的iteam布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#FFFFFF"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginTop="5dp"
    android:visibility="visible"
    android:layout_height="wrap_content">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:id="@+id/scsc"
        android:layout_height="match_parent">
        <CheckBox
            android:id="@+id/selectt"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginStart="5dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/photo"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:src="@drawable/ic_launcher_background"
            android:id="@+id/photo"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="68dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="11dp"
            android:layout_marginTop="7dp"
            android:text="商品名字"
            app:layout_constraintStart_toEndOf="@+id/photo"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/text_ms"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:layout_marginTop="4dp"
            android:text="对商品描叙"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/text1"
            app:layout_constraintTop_toBottomOf="@+id/text1" />

        <TextView
            android:id="@+id/price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:text="100"
            android:textColor="#FF9800"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="@+id/text_ms" />

        <ImageView
            app:srcCompat="@drawable/jian"
            android:id="@+id/ptoto_down"
            android:layout_width="30dp"
            android:layout_height="15dp"
            android:layout_marginStart="3dp"
            android:layout_marginBottom="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/text_ms"
            app:layout_constraintTop_toTopOf="@+id/Categorynum"
            app:layout_constraintVertical_bias="0.0"
            />

        <TextView
            android:textColor="#000000"
            android:id="@+id/Categorynum"
            android:layout_width="38dp"
            android:layout_height="16dp"
            android:layout_marginBottom="40dp"
            android:autoText="false"
            android:gravity="center"
            android:text="0"
            android:textAllCaps="false"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/ptoto_down" />

        <ImageView
            android:id="@+id/photo_add"
            android:layout_width="30dp"
            android:layout_height="15dp"
            app:layout_constraintBottom_toBottomOf="@+id/Categorynum"
            app:layout_constraintStart_toEndOf="@+id/Categorynum"
            app:srcCompat="@drawable/jia" />
    </androidx.constraintlayout.widget.ConstraintLayout>


</LinearLayout>

这里面注意用一个线性布局或者约束者布局包裹起来并且给你一个ID

3.适配器代码

 View inflate = LayoutInflater.from(getContext()).inflate(R.layout.delete, null);
    TextView textView = inflate.findViewById(R.id.tv_delete);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            GWC_fhz_Fragment.mList.remove(d);
        }
    });
    SmartSwipe.wrap(b.getView(R.id.scsc))
            .addConsumer(new SlidingConsumer())
            //滑动的距离
            .setRelativeMoveFactor(0.5F)
            //滑动之后展示到view
            .setHorizontalDrawerView(inflate)
            //颜色
            .setScrimColor(0x2F000000)
            .enableHorizontal();

可以不需要点击方法,我自己写了个点击删除

4.效果

请添加图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码主要是在Vue中实现了购物车中的左删除效果。当点击红色区域时,会触发删除操作。具体的实现逻辑如下: - 在handleDelete方法中,首先会显示一个提示框,确认是否删除该商品。 - 如果确认删除,则会进行身份验证,确保用户已登录。 - 然后通过axios发送DELETE请求来删除该商品。 - 如果删除成功,则通过$emit方法触发getList事件,更新购物车列表。 - 如果删除失败,则会显示一个删除商品失败的提示。 此外,还引用了另外两个内容: - [2介绍了使用Vue实现移动端左删除效果的方法,对于实现左删除功能有一定的参考价值。 - [3介绍了滑动删除的原理,通过监听touch事件来判断左还是右,并根据滑动方向来显示或隐藏删除按钮。 所以,以上代码是实现Vue购物车左删除功能的一种方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [mpvue实现小程序购物车左删除功能](https://blog.csdn.net/qq_36070288/article/details/84881644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [使用Vue实现移动端左删除效果附](https://download.csdn.net/download/weixin_38697979/12942257)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [vue实现购物车页面功能交互,单选、全选、左删除](https://blog.csdn.net/cd13849109771/article/details/120987420)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值