仿IOS的越界回彈效果和左右滑動(dòng)功能
最初的本意是做一個(gè)TimeLine時(shí)間軸,到后來逐漸成為了一個(gè)側(cè)滑的自定義控件。也很感謝大家的支持,所以趁著年初有空閑,重構(gòu)了當(dāng)前項(xiàng)目。以后也會(huì)逐漸完善和維護(hù)本項(xiàng)目并提供maven依賴,再次感謝!




Feature
SwipeDragLayout使用ViewDragHelper來進(jìn)行滑動(dòng)操作,代碼少,易理解,核心代碼不過150行
使用了保留一個(gè)靜態(tài)類的方法來確保只有一個(gè)展開,并在onDetachedFromWindow方法中進(jìn)行關(guān)閉操作
提供了多種自定義屬性,見下表
sample使用了DataBinding和kotlin 進(jìn)行了多類型的綁定,對于了解和使用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>
注意:暫時(shí)只支持兩個(gè)子View,一個(gè)content,一個(gè)側(cè)滑的menu,以后會(huì)支持
回調(diào)監(jiān)聽
public interface SwipeListener {
/**
* 拖動(dòng)中,可根據(jù)offset 進(jìn)行其他動(dòng)畫
* @param layout
* @param offsetRatio 偏移相對于menu寬度的比例
* @param offset 偏移量px
*/
void onUpdate(SwipeDragLayout layout, float offsetRatio, float offset);
/**
* 展開完成
* @param layout
*/
void onOpened(SwipeDragLayout layout);
/**
* 關(guān)閉完成
* @param layout
*/
void onClosed(SwipeDragLayout layout);
}
相關(guān)文章
safari調(diào)試iOS app web頁面的步驟
這篇文章主要為大家詳細(xì)介紹了safari調(diào)試iOS app web頁面的步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
iOS開發(fā)之MRC(手動(dòng)內(nèi)存管理)詳解
這篇文章主要介紹了?iOS開發(fā)之MRC(手動(dòng)內(nèi)存管理)詳解的相關(guān)資料,需要的朋友可以參考下2022-08-08
iOS開發(fā)之使用Storyboard預(yù)覽UI在不同屏幕上的運(yùn)行效果
使用Storyboard做開發(fā)效率非常高,為了防止在團(tuán)隊(duì)中發(fā)生沖突,采取的解決辦法是負(fù)責(zé)UI開發(fā)的同事最好每人維護(hù)一個(gè)Storyboard, 公用的組件使用輕量級(jí)的xib或者純代碼來實(shí)現(xiàn),下面小編就給大家介紹如何使用Storyboard預(yù)覽UI在不同屏幕上的運(yùn)行效果,需要的朋友可以參考下2015-08-08
iOS9蘋果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法
這篇文章主要介紹了iOS9蘋果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法的相關(guān)資料,需要的朋友可以參考下2016-01-01
iOS開發(fā)中Swift3 監(jiān)聽UITextView文字改變的方法(三種方法)
在項(xiàng)目中使用文本輸入框出UITextField之外還會(huì)經(jīng)常使用 UITextView ,難免會(huì)有需求監(jiān)聽UITextView文本框內(nèi)文本數(shù)量.下面介紹在swift3中兩種常用方式,需要的朋友參考下吧2016-11-11
IOS 開發(fā)之ObjectiveC的變量類型的字符代表
這篇文章主要介紹了IOS 開發(fā)之ObjectiveC的變量類型的字符代表的相關(guān)資料,這里舉例說明如何使用Objective的變量類型的字符,幫助大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下2017-08-08
iOS 數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組的操作方法
這篇文章主要介紹了iOS 數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組的操作方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-07-07

