SlideLayout:超級迷你輕量級全方向完美側滑控件(Android)

分類:技術 時間:2017-01-13

SlideLayout

純手工超級迷你輕量級全方向完美滑動處理側滑控件(比官方 support v4 包 SlidingPaneLayout 控件更加 Q 迷你,累計代碼不足 300 行),支持上下左右有各種側拉,可配置側拉松手臨界距離,支持單獨使用、ListView、GridView、RecycleView、ScrollView、ViewPager 等各種嵌套(作為 item 使用或者作為以上所有控件的父容器使用),具體不同配置展示效果如下圖。

說明文檔

如下是關于 SlideLayout 的相關使用方式、屬性說明、拓展自定義的解釋說明。

使用樣例

實現類似手機 QQ 側滑效果,ListView 向右側滑拉出側邊欄。

lt;cn.yan.library.SlideLayout
    android:layout_width=quot;match_parentquot;
    android:layout_height=quot;match_parentquot;
    app:slideDirection=quot;fromLeftquot;
    app:slideCriticalValue=http://www.tuicool.com/articles/quot;50dpquot;gt;
    lt;ListView
        android:layout_width=quot;match_parentquot;
        android:layout_height=quot;match_parentquot;
        android:entries=quot;@array/demo_arrayquot;/gt;

    lt;TextView
        android:background=quot;@android:color/holo_red_lightquot;
        android:layout_width=quot;100dpquot;
        android:layout_height=quot;match_parentquot;
        android:text=quot;我是側滑區域quot;/gt;
lt;/cn.yan.library.SlideLayoutgt;

實現類似手機 QQ ListView 聊天列表任意 item 向左滑動呼出刪除按鈕效果。

lt;cn.yan.library.SlideLayout
    android:layout_width=quot;match_parentquot;
    android:layout_height=quot;80dpquot;gt;
    lt;TextView
        android:id=quot;@ id/content_idquot;
        android:gravity=quot;centerquot;
        android:layout_width=quot;match_parentquot;
        android:layout_height=quot;match_parentquot;/gt;

    lt;LinearLayout
        android:layout_width=quot;200dpquot;
        android:layout_height=quot;match_parentquot;
        android:orientation=quot;horizontalquot;gt;
        lt;TextView
            android:id=quot;@ id/slide_idquot;
            android:background=quot;@android:color/holo_blue_darkquot;
            android:layout_width=quot;100dpquot;
            android:layout_height=quot;match_parentquot;
            android:text=quot;刪除quot;/gt;

        lt;TextView
            android:id=quot;@ id/slide1_idquot;
            android:background=quot;@android:color/holo_green_darkquot;
            android:layout_width=quot;100dpquot;
            android:layout_height=quot;match_parentquot;
            android:text=quot;收藏quot;/gt;
    lt;/LinearLayoutgt;
lt;/cn.yan.library.SlideLayoutgt;

已實現類說明

類別 類名 說明
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 布局,默認不可見;切記兩個子控件所處順序,子控件層級不限,具體模板如下:

lt;cn.yan.library.SlideLayout
    android:layout_width=quot;match_parentquot;
    android:layout_height=quot;match_parentquot;gt;
    lt;控件一(Content),不限嵌套層級等,默認可見/gt;

    lt;控件二(slide),不限嵌套層級等,默認不可見/gt;
lt;/cn.yan.library.SlideLayoutgt;

License 聲明

MIT License

Copyright (c) 2016 yanbo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the quot;Softwarequot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED quot;AS ISquot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Tags: 安卓開發

文章來源:https://github.com/yanbober/SlideLayout


ads
ads

相關文章
ads

相關文章

ad