Android開源:SlideLayout-超級迷你輕量級全方向完美側滑控件
SlideLayout
純手工超級迷你輕量級全方向完美滑動處理側滑控件(比官方 support v4 包 SlidingPaneLayout 控件更加 Q 迷你,累計代碼不足 300 行),支持上下左右有各種側拉,可配置側拉松手臨界距離,支持單獨使用、ListView、GridView、RecycleView、ScrollView、ViewPager 等各種嵌套(作為 item 使用或者作為以上所有控件的父容器使用),具體不同配置展示效果如下圖。
說明文檔
如下是關于 SlideLayout 的相關使用方式、屬性說明、拓展自定義的解釋說明。
使用樣例
實現類似手機 QQ 側滑效果,ListView 向右側滑拉出側邊欄。
<cn.yan.library.SlideLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:slideDirection="fromLeft"
app:slideCriticalValue="50dp">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/demo_array"/>
<TextView
android:background="@android:color/holo_red_light"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="我是側滑區域"/>
</cn.yan.library.SlideLayout></code></pre>
實現類似手機 QQ ListView 聊天列表任意 item 向左滑動呼出刪除按鈕效果。
<cn.yan.library.SlideLayout
android:layout_width="match_parent"
android:layout_height="80dp">
<TextView
android:id="@+id/content_id"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/slide_id"
android:background="@android:color/holo_blue_dark"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="刪除"/>
<TextView
android:id="@+id/slide1_id"
android:background="@android:color/holo_green_dark"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="收藏"/>
</LinearLayout>
</cn.yan.library.SlideLayout></code></pre>
已實現類說明
類別
類名
說明
library
SlideLayout
支持配置各種方向側滑和各種嵌套或者被嵌套的側滑控件。
屬性說明
屬性
含義
app:slideCriticalValue
SlideLayout 任意方向側滑拉出多大距離后松手敏感距離,譬如側滑大于 50dp 后松手則自動滑開,小于 50 dp 內松手則自動收起;不設置默認為 SlideLayout 控件第二個子成員 width 的二分之一。
app:slideDirection
側滑從哪邊拉出,默認為從右側拉出,可取值為 fromRight、fromLeft、fromTop、fromBottom。
SlideLayout 提供方法說明
方法
說明
int getSlideState()
獲取當前側滑控件所處狀態,STATE_CLOSE、STATE_SLIDING、STATE_OPEN。
void smoothCloseSlide()
平滑的收起側滑。
void smoothOpenSlide()
平滑的打開側滑。
SlideLayout 使用注意事項
SlideLayout 控件有且必須包含兩個子控件,第一個為 content 布局,默認撐滿整個 SlideLayout,第二個為 slide 布局,默認不可見;切記兩個子控件所處順序,子控件層級不限,具體模板如下:
<cn.yan.library.SlideLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<控件一(Content),不限嵌套層級等,默認可見/>
<控件二(slide),不限嵌套層級等,默認不可見/>
</cn.yan.library.SlideLayout></code></pre>
本文由用戶 myqq9877 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!