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

2025-05-29 0 65

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

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

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

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

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

feature

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

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

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

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

自定义属性

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69
<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,以后会支持

回调监听

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22
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);

}

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 仿IOS的越界回弹效果和左右滑动功能 https://www.kuaiidc.com/89865.html

相关文章

发表评论
暂无评论