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




Feature
SwipeDragLayout使用ViewDragHelper來進行滑動操作,代碼少,易理解,核心代碼不過150行
使用了保留一個靜態(tài)類的方法來確保只有一個展開,并在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,以后會支持
回調監(jiān)聽
public interface SwipeListener {
/**
* 拖動中,可根據(jù)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);
}
相關文章
iOS開發(fā)之使用Storyboard預覽UI在不同屏幕上的運行效果
使用Storyboard做開發(fā)效率非常高,為了防止在團隊中發(fā)生沖突,采取的解決辦法是負責UI開發(fā)的同事最好每人維護一個Storyboard, 公用的組件使用輕量級的xib或者純代碼來實現(xiàn),下面小編就給大家介紹如何使用Storyboard預覽UI在不同屏幕上的運行效果,需要的朋友可以參考下2015-08-08
iOS9蘋果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法
這篇文章主要介紹了iOS9蘋果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法的相關資料,需要的朋友可以參考下2016-01-01
iOS開發(fā)中Swift3 監(jiān)聽UITextView文字改變的方法(三種方法)
在項目中使用文本輸入框出UITextField之外還會經(jīng)常使用 UITextView ,難免會有需求監(jiān)聽UITextView文本框內文本數(shù)量.下面介紹在swift3中兩種常用方式,需要的朋友參考下吧2016-11-11
IOS 開發(fā)之ObjectiveC的變量類型的字符代表
這篇文章主要介紹了IOS 開發(fā)之ObjectiveC的變量類型的字符代表的相關資料,這里舉例說明如何使用Objective的變量類型的字符,幫助大家學習理解這部分內容,需要的朋友可以參考下2017-08-08
iOS 數(shù)據(jù)結構之數(shù)組的操作方法
這篇文章主要介紹了iOS 數(shù)據(jù)結構之數(shù)組的操作方法,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2018-07-07

