OverScroll
利用CoordinatorLayout+Behavior实现列表弹性滚动和惯性滚动效果(类似微信首页),支持水平和垂直方向的滚动,效果如下:
vertical over-scrollhorizontal over-scroll
[图片上传失败...(image-a1e896-1552728765518)]
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!
网友评论