OverScroll
利用CoordinatorLayout+Behavior實現列表彈性滾動和慣性滾動效果(類似微信首頁),支援水平和垂直方向的滾動,效果如下:
Usage 用法
Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.1993hzw:OverScroll:1.1.1'
}
複製程式碼
在xml佈局檔案中新增類似程式碼:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<cn.forward.overscroll.view.OverScrollVerticalRecyclerView
android:background="#0ff"
android:id="@+id/overscroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
...
</android.support.design.widget.CoordinatorLayout>
複製程式碼
當然你可以在CoordinatorLayout
中使用OverScrollHorizontalRecyclerView
, OverScrollVerticalRecyclerView
或 OverScrollScrollView
.
現在你的佈局就實現了彈性滾動和慣性滾動效果啦!
擴充
你還可以擴充該控制元件以實現更復雜的互動效果,設定 IOverScrollCallback 或者新增 IOffsetChangeListener.
IOverScrollView overScrollView = findViewById(R.id.overscroll_view);
overScrollView.setOverScrollCallback(new IOverScrollCallback() {
@Override
public boolean canScroll(IOverScroll overScroll, View child, int scrollDirection) {
...
}
@Override
public int getMaxFlingOffset(IOverScroll overScroll, View child, int scrollDirection) {
...
}
@Override
public float getDampingFactor(IOverScroll overScroll, View child, int scrollDirection) {
...
}
@Override
public int getMinFlingVelocity(IOverScroll overScroll, View child, int scrollDirection) {
...
}
@Override
public void onOffsetChanged(IOverScroll overScroll, View child, int offset) {
...
}
@Override
public boolean onSpringBack(IOverScroll overScroll, View child) {
...
}
@Override
public void onStopSpringingBack(IOverScroll overScroll, View child) {
...
}
});
overScrollView.addOffsetChangeListener(new IOffsetChangeListener() {
@Override
public void onOffsetChanged(View child, int offset) {
...
}
});
複製程式碼
(預設IOverScrollCallback
介面的實現為SimpleOverScrollCallback)
專案地址OverScroll
多謝支援我的github專案>>>OverScroll!