当前位置: 移动技术网 > IT编程>移动开发>IOS > 仿IOS的越界回弹效果和左右滑动功能

仿IOS的越界回弹效果和左右滑动功能

2019年07月24日  | 移动技术网IT编程  | 我要评论

纸客帝国官网,jiqingxi,万宝路香烟价格

最初的本意是做一个timeline时间轴,到后来逐渐成为了一个侧滑的自定义控件。也很感谢大家的支持,所以趁着年初有空闲,重构了当前项目。以后也会逐渐完善和维护本项目并提供maven依赖,再次感谢!

feature

swipedraglayout使用viewdraghelper来进行滑动操作,代码少,易理解,核心代码不过150行

使用了保留一个静态类的方法来确保只有一个展开,并在ondetachedfromwindow方法中进行关闭操作

提供了多种自定义属性,见下表

sample使用了databinding和kotlin 进行了多类型的绑定,对于了解和使用databinding大有益处,添加多种type更是十分简单,再也不用extends recyclerview.adapter了

自定义属性

<com.ditclear.swipelayout.swipedraglayout
        android:id="@+id/swip_layout"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:swipe_direction="left"
        app:swipe_enable="true"
        app:ios="true">

      <linearlayout
          android:id="@+id/content_layout"
          android:layout_width="match_parent"
          android:layout_height="60dp"
          android:background="#ffffff"
          android:gravity="center_vertical"
          android:orientation="horizontal"
          android:tag="content">

        <imageview
            android:id="@+id/iv_type"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginleft="@dimen/activity_horizontal_margin"
            android:background="@drawable/type_edit"
            android:scaletype="centerinside"
            android:onclick="@{(v)->presenter.onitemclick(v,item)}"
            android:src="@mipmap/edit"/>

        <textview
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:ellipsize="end"
            android:gravity="center_vertical|right"
            android:maxlines="1"
            android:paddingright="@dimen/activity_horizontal_margin"
            android:onclick="@{(v)->presenter.onitemclick(v,item)}"
            android:text="@{item.content}"
            android:textcolor="#000000"
            tools:text="this is content"/>
      </linearlayout>

      <linearlayout
          android:id="@+id/menu_layout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:tag="menu">

        <imageview
            android:id="@+id/trash"
            android:layout_width="70dp"
            android:layout_height="60dp"
            android:background="#ff6347"
            android:paddingleft="25dp"
            android:onclick="@{(v)->presenter.onitemclick(v,item)}"
            android:paddingright="25dp"
            android:src="@mipmap/trash"/>

        <imageview
            android:id="@+id/star"
            android:layout_width="70dp"
            android:layout_height="60dp"
            android:background="#4cd964"
            android:paddingleft="22dp"
            android:paddingright="22dp"
            android:onclick="@{(v)->presenter.onitemclick(v,item)}"
            android:src="@mipmap/star"/>
      </linearlayout>
    </com.ditclear.swipelayout.swipedraglayout>

注意:暂时只支持两个子view,一个content,一个侧滑的menu,以后会支持

回调监听

public interface swipelistener {

    /**
     * 拖动中,可根据offset 进行其他动画
     * @param layout
     * @param offsetratio 偏移相对于menu宽度的比例
     * @param offset 偏移量px
     */
    void onupdate(swipedraglayout layout, float offsetratio, float offset);

    /**
     * 展开完成
     * @param layout
     */
    void onopened(swipedraglayout layout);

    /**
     * 关闭完成
     * @param layout
     */
    void onclosed(swipedraglayout layout);
  }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网