国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

仿IOS的越界回彈效果和左右滑動功能

2019-10-21 18:41:47
字體:
供稿:網(wǎng)友

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

IOS,越界回彈效果,左右滑動

IOS,越界回彈效果,左右滑動

IOS,越界回彈效果,左右滑動

IOS,越界回彈效果,左右滑動

Feature

SwipeDragLayout使用ViewDragHelper來進(jìn)行滑動操作,代碼少,易理解,核心代碼不過150行

使用了保留一個靜態(tài)類的方法來確保只有一個展開,并在onDetachedFromWindow方法中進(jìn)行關(guān)閉操作

提供了多種自定義屬性,見下表

sample使用了DataBinding和kotlin 進(jìn)行了多類型的綁定,對于了解和使用DataBinding大有益處,添加多種Type更是十分簡單,再也不用extends RecyclerView.Adapter了

自定義屬性

IOS,越界回彈效果,左右滑動

<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,一個側(cè)滑的menu,以后會支持

回調(diào)監(jiān)聽

public interface SwipeListener {    /**     * 拖動中,可根據(jù)offset 進(jìn)行其他動畫     * @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)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 同江市| 东安县| 崇阳县| 谢通门县| 察哈| 朝阳市| 琼中| 阿鲁科尔沁旗| 上杭县| 阳泉市| 吴堡县| 金门县| 太湖县| 襄樊市| 图片| 五家渠市| 崇礼县| 从江县| 桂林市| 新绛县| 四平市| 介休市| 合江县| 绥芬河市| 福清市| 龙州县| 竹山县| 遂川县| 历史| 华宁县| 鄂托克前旗| 明星| 松滋市| 新竹市| 晋中市| 尉氏县| 公安县| 衡阳县| 江孜县| 灵山县| 惠来县|