这是一个布局刷新控件,滑动到最顶部刷新,滑动到最底部加载更多,用法:
1.添加依赖
compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.1'
compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.1'
2.布局文件
<?xml version="1.0" encoding="utf-8"?>
<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:background="#fff" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
3.类文件使用
class IndexActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_index)
refreshLayout.setOnRefreshListener {
//刷新
refreshLayout.finishRefresh(2000)
}
refreshLayout.setOnLoadmoreListener{
//加载
refreshLayout.finishLoadmore(2000)
}
////可不设置,有默认样式
//设置 Header 为 Material风格
refreshLayout.refreshHeader = MaterialHeader(this).setShowBezierWave(true)
//设置 Footer 为 球脉冲
refreshLayout.refreshFooter = BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale)
porcessAndroidLollipop()
}
/**
* 沉浸式状态栏实现,5.0>
*/
private fun porcessAndroidLollipop() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 全透明实现
val window = window
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT
}
}
}
完了,就是这么简单
这个控件功能远远不如这些,有兴趣的可以去这位大神的github看看SwipeRefreshLayout的GitHub