第三方SwipeDelMenuLayout:进行左右滑动操作后显示出指定控件

效果如图:


学习别人的程序源代码,发现这款开源框架,特此记录一下使用方法。
不知道博主是谁,所以找另外一个和此很相似的一个博客来学习:【Android】毫无耦合性,一个Item根布局搞定 item侧滑删除菜单,像IOS那样简单的使用侧滑删除。 - zxt0601的博客 - CSDN博客 http://blog.csdn.net/zxt0601/article/details/52303781

使用具体步骤:

1.在app的gradle中添加依赖:
在android中添加:

repositories {
        maven {
            url "https://jitpack.io"
        }
    }

在dependencies中添加

compile 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'

2.布局xml的使用:
在为列表项写布局文件时,直接在最外层使用SwipeMenuLayout ,内部第一个控件为正常显示的内容,从第二个控件开始就全部是侧滑显示的内容。

<?xml version="1.0" encoding="utf-8"?>
<com.mcxtzhang.swipemenulib.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/item_list_view"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    app:ios="false">
    <!-- 在本控件内依次排列ContentItem、菜单即可-->
    <!-- ContentItem为 TextView -->
    <TextView
        android:id="@+id/tv_sample_name"
        android:singleLine="true"
        android:ellipsize="end"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="@color/app_sample_name"
        android:textSize="@dimen/large_size"/>
    <!-- 以下都是侧滑菜单的内容依序排列 -->
    <Button
        android:id="@+id/btn_edit_sample"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:background="#d9dee4"
        android:text="编辑"
        android:textColor="@android:color/white"/>

    <Button
        android:id="@+id/btn_delete_sample"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:background="@color/app_red"
        android:text="删除"
        android:textColor="@android:color/white"/>
</com.mcxtzhang.swipemenulib.SwipeMenuLayout>
 holder.itemListView.smoothClose();//关闭侧滑效果,有反方向滑动动画效果
 holder.itemListView.quickClose();//直接关闭侧滑,无动画效果

补充:

此框架可用于任何你想实现通过滑动操作后显示出相应控件的地方,举例如下:
效果图:

界面两个红色区域皆为textview;只有蓝色区域使用了框架。
布局xml:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:background="@color/colorAccent"/>

    <com.mcxtzhang.swipemenulib.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/item_list_view"
        android:layout_marginTop="10dp"
        android:background="@color/colorPrimary"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:clickable="true"
        app:ios="false">
        <!-- 在本控件内依次排列ContentItem、菜单即可-->
        <!-- ContentItem为 TextView -->
        <TextView
            android:id="@+id/tv_sample_name"
            android:singleLine="true"
            android:ellipsize="end"
            android:text="9999999"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <!-- 以下都是侧滑菜单的内容依序排列 -->
        <Button
            android:id="@+id/btn_edit_sample"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:background="#d9dee4"
            android:text="编辑"
            android:textColor="@android:color/white"/>

        <Button
            android:id="@+id/btn_delete_sample"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:text="删除"
            android:textColor="@android:color/white"/>
    </com.mcxtzhang.swipemenulib.SwipeMenuLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:layout_marginTop="10dp"
        android:background="@color/colorAccent"/>

</LinearLayout>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值