0
点赞
收藏
分享

微信扫一扫

[Android Material Design]组件07 - SwipeRefreshLayout

文章目录

效果图

SwipeRefreshLayout

关键代码

xml布局文件代码如下:

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/srl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="下拉刷新!" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

SwipeRefreshLayout是一个容器视图,里面可以放listviewrecyclerview等控件。当用户下拉控件时,刷新控件的内容。
kotlin逻辑代码如下:

val srl = findViewById<SwipeRefreshLayout>(R.id.srl)
val tv = findViewById<TextView>(R.id.tv)
srl.setColorSchemeColors(ContextCompat.getColor(this, android.R.color.holo_red_dark),
		ContextCompat.getColor(this, android.R.color.holo_orange_dark),
		ContextCompat.getColor(this, android.R.color.holo_blue_dark))
srl.setOnRefreshListener {
	srl.postDelayed({
		srl.isRefreshing = false
		tv.text = "刷新成功"
	}, 3000)
}

SwipeRefrshLayout控件可以实现下拉刷新的效果,基本使用的方法如下:

源码地址

https://github.com/yurensan/MaterialDesignDemo

举报

相关推荐

0 条评论