android自定义侧滑LisitView(包含编辑、删除)

      (尊重原创转载请说明来处,谢谢)

       最近由于项目的需要,自定义了一个具有侧滑功能的listview,侧滑后可以点击编辑、删除。好了,大家先看一下效果图,毕竟是看脸的世界哭



好了,我要先讲一下思路,一次编辑很难完善,有什么问题我后来还会补上,欢迎各位大神拍砖:

1:首先先说一下item:item用的LinearLayout布局,删除、编辑分别是写死了宽度的TextView,左边是一个match_parent的RelativeLayout,内容自己随意搞

2:上下滑动和左右滑动的处理:当用户手指滑动时,可以进行坐标的判断,如果Y轴移动距离大,则listview上下滑动;否则当X轴移动距离达到或者超过一个TextView的宽度时,动态控制item的marginLeft为负的两倍TextView的宽度,从而实现滑动效果

3:编辑、删除的点击:编辑、删除在adapter中进行监听,然后自己在adapter中再定义一个监听接口,方便用户在使用listview的activity中进行监听


下面附上item的布局文件:

<?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="wrap_content"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/rlTop"
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:padding="10dp">
            <ImageView
                android:id="@+id/imgLamp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="10dp"
                android:src="@mipmap/ic_launcher"
                android:layout_width="40dp"
                android:layout_height="40dp"/>
            <TextView
                android:id="@+id/tvName"
                android:layout_width="wrap_content"
                android:layout_height="22dp"
          
  • 23
    点赞
  • 87
    收藏
    觉得还不错? 一键收藏
  • 24
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值