SlidingLayout是一種Android平臺的View控件,可以幫助你實(shí)現(xiàn)類似微信網(wǎng)頁瀏覽的下拉功能,也可以幫助你實(shí)現(xiàn)類似iOS中UITableView的下拉上拉彈跳的果凍效果。
SlidingLayout完美兼容Android自帶庫和兼容庫的所有View組件,包括RecyclerView、ListView、ScrollView以及WebView等等。
SlidingLayout簡單易用,最低支持Android api v9。
Project site: https://github.com/HomHomLin/SlidingLayout.
Demo: https://github.com/HomHomLin/SlidingLayout/tree/master/demo.
圖片.png
- Gradle dependency:
compile 'homhomlin.lib:sldinglayout:0.9.0'
如果你的項(xiàng)目需要支持API V9,你需要添加以下依賴:
compile 'com.nineoldandroids:library:2.4.0'
SlidingLayout的使用非常簡單,你只需要將你想實(shí)現(xiàn)的控件在XML布局中嵌套進(jìn)SlidingLayout即可,如你需要讓ListView實(shí)現(xiàn)果凍效果:
1.創(chuàng)建背景View的xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8c8c8e"
android:gravity="top"
android:textSize="12sp"
android:textColor="#f5f3f3"
android:padding="16dp"
android:text="developed by HomhomLin"/>
2.將你的控件放進(jìn)SlidingLayout中
注意布局需要res-auto命名空間,注意將自己的控件設(shè)置一個背景,否則會將背景View透視出來。
<?xml version="1.0" encoding="utf-8"?>
<lib.homhomlib.design.SlidingLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slidingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:sliding_mode="both"
app:background_view="@layout/view_bg">
<!--background_view為你的背景布局-->
<ListView
android:id="@+id/listview"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</lib.homhomlib.design.SlidingLayout>
XML樣式參數(shù)
background_view 背景view
sliding_mode 滑動模式,both為上下可彈跳,top為頂部彈跳,bottom為底部彈跳,默認(rèn)為both
sliding_pointer_mode 手指模式,one為只識別一個手指,more為支持多指滑動,默認(rèn)為more
top_max 當(dāng)滑動模式為top時才有效,用于可滑動的最大距離,如"top_max:200dp",默認(rèn)為-1(不限制)
常用API
public void setSlidingOffset(float slidingOffset) 設(shè)置控件的滑動阻力,有效值為0.1F~1.0F,值越小阻力越大,默認(rèn)為0.5F
public void setTargetView(View view) 設(shè)置控件的前景View
public void setBackgroundView(View view) 設(shè)置控件的背景View
public void setSlidingListener(SlidingListener slidingListener) 給控件設(shè)置監(jiān)聽,可以監(jiān)聽滑動情況
public void setSlidingMode(int mode) 設(shè)置滑動模式
public void setSlidingDistance(int max) 設(shè)置最大滑動距離,僅在top模式下有效