仿IOS左滑 删除 编辑

在这里插入图片描述
在这里插入图片描述

目前我是设置两个按钮,可以根据自己的需求继续增加 实现步骤如下:

第一步 添加依赖

 	//仿苹果滑动删除
    implementation 'com.github.anzaizai:EasySwipeMenuLayout:1.1.4'

第二步:添加一个常用的 RecyclerView

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/transparent" />

第三步:新建一个适配器自定义布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
    android:orientation="vertical">

    <com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout
        android:id="@+id/es"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentView="@+id/content"
        app:rightMenuView="@+id/right">

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

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:orientation="vertical"
                    android:paddingLeft="20dp"
                    android:paddingTop="15dp"
                    android:paddingBottom="15dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/item_address_model"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:background="@drawable/shape_round_gray"
                            android:paddingLeft="5dp"
                            android:paddingRight="5dp"
                            android:text="默认"
                            android:textColor="@color/white"
                            android:textSize="13sp"
                            android:textStyle="bold"
                            android:visibility="gone" />

                        <TextView
                            android:id="@+id/item_address_address"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:text="张三"
                            android:textColor="@color/black"
                            android:textSize="16sp"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/item_address_name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="5dp"
                        android:text="张三"
                        android:textColor="@color/xian"
                        android:textSize="14sp"
                        android:textStyle="normal" />


                </LinearLayout>

                <ImageView
                    android:id="@+id/item_ima_address_eit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|right"
                    android:padding="20dp"
                    android:src="@mipmap/a_address_edit" />
            </FrameLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1px"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@color/xian_news" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/right_menu_1"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:background="@android:color/darker_gray"
                android:gravity="center"
                android:text="设为\n默认"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:textStyle="normal" />


            <TextView
                android:id="@+id/right_menu_2"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:background="@color/red"
                android:gravity="center"
                android:text="删除"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:textStyle="normal" />
        </LinearLayout>
    </com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout>
</LinearLayout>

第四步 适配器代码就是常规的适配器 只需要写进去添加

    mAdapter.addChildClickViewIds(
            R.id.content,
            R.id.right_menu_1,
            R.id.right_menu_2,
            R.id.item_ima_address_eit
        )

第五步 点击事件

   mAdapter.setOnItemChildClickListener { _, view, position ->

            when (view.id) {
                R.id.content -> {
                  
                }
               
                R.id.right_menu_1 -> {
                  
                }

                R.id.right_menu_2 -> {
                    showDialog("删除", "确定要删除地址么?", position)
                }
            }
        }
***注意
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android仿iOS桌面应用删除动画可以使用属性动画实现。以下是一个简单的实现步骤: 1. 创建一个布局文件,用于显示要删除的应用图标。在这个布局中,你可以使用ImageView来显示应用图标,然后添加一个TextView来显示删除提示。 2. 在Java代码中,使用属性动画设置ImageView的透明度和缩放比例。通过逐渐降低透明度和缩放比例,可以创建一个逐渐消失的效果。 3. 在动画结束时,删除应用程序,并在屏幕上显示一个Snackbar或Toast,以显示已删除的应用程序名称。 下面是一个示例代码,可以让你更好地了解如何实现这个功能: ```java public class DeleteAnimationActivity extends AppCompatActivity { private ImageView mAppIcon; private TextView mDeleteHint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_delete_animation); mAppIcon = findViewById(R.id.iv_app_icon); mDeleteHint = findViewById(R.id.tv_delete_hint); // 设置属性动画 ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mAppIcon, "alpha", 1f, 0f); ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleX", 1f, 0f); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleY", 1f, 0f); // 设置动画集合 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator); animatorSet.setDuration(500); // 监听动画结束事件 animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // 删除应用程序 deleteApp(); // 显示Snackbar或Toast Snackbar.make(mAppIcon, "已删除应用程序", Snackbar.LENGTH_LONG).show(); } }); // 启动动画 animatorSet.start(); } private void deleteApp() { // 删除应用程序的代码 } } ``` 在上面的代码中,我们使用 ObjectAnimator 来设置透明度和缩放比例的动画,然后使用 AnimatorSet 将它们组合在一起。在动画结束时,我们删除应用程序并显示一个Snackbar或Toast。 如果你想要更加复杂的删除动画效果,可以尝试使用 PathInterpolator 或自定义 Interpolator 来控制动画的速度和加速度。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值