仿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)行了多類型的綁定,對(duì)于了解和使用DataBinding大有益處,添加多種Type更是十分簡(jiǎn)單,再也不用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 偏移相對(duì)于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)文章
iOS開發(fā)中使用Quartz2D繪圖及自定義UIImageView控件
這篇文章主要介紹了iOS開發(fā)中使用Quartz2D繪圖及自定義UIImageView控件的方法,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-11-11
iOS10 widget實(shí)現(xiàn)3Dtouch 彈出菜單
這篇文章主要介紹了 iOS10 widget實(shí)現(xiàn)3Dtouch 彈出菜單的相關(guān)資料,需要的朋友可以參考下2016-12-12
IOS開發(fā)教程之put上傳文件的服務(wù)器的配置及實(shí)例分享
IOS開發(fā)給人一種高大上的趕腳,弄的好像你不會(huì)IOS就不是個(gè)合格的程序員一樣,好吧,既然是大趨勢(shì),那我們就來學(xué)習(xí)下吧,今天來看看put上傳文件的服務(wù)器配置及案例2014-06-06
iOS實(shí)現(xiàn)多個(gè)垂直滑動(dòng)條并列視圖
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)多個(gè)垂直滑動(dòng)條并列視圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
iOS13即將到來,iOS推送DeviceToken適配方案詳解
這篇文章主要介紹了iOS13即將到來,iOS推送DeviceToken適配方案詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
iOS 動(dòng)畫 —— 禮花效果實(shí)例詳細(xì)
這篇文章主要介紹了iOS 動(dòng)畫 —— 禮花效果實(shí)例詳細(xì)的相關(guān)資料,需要的朋友可以參考下2016-09-09

