SwipeRefreshLayout上拉下拉框架简单使用

这是一个布局刷新控件,滑动到最顶部刷新,滑动到最底部加载更多,用法:

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,935评论 25 709
  • -1- 因为参加拉丁舞百日打卡,特意去报了个拉丁培训班。 在这...
    旖旎风光护你行阅读 3,345评论 2 0
  • 那晚, 做了一个梦。 梦见你也在我的梦里, 你说你喜欢我, 而梦里的我也是喜欢你的。 在梦境中, 我们彼此缠绵, ...
    小燕姿阅读 1,449评论 0 2
  • __block NSInteger second = self.second; //全局队列 默认优先级 dis...
    H了M阅读 1,534评论 0 0