繁体   English   中英

recyclerView 如何自定义拉取刷新? (不是滑动刷新)

[英]How to make Custom Pull to refresh for recyclerView? (Not Swipe to refresh)

我需要这个自定义下拉菜单来刷新布局。 我如何为 Android 开发这个? 请确保我想要的正是这种行为,而不是 Android 本机滑动刷新。

在此处输入图像描述

为此,您可以使用库。 我找到了适合我的https://github.com/SimformSolutionsPvtLtd/SSPullToRefresh 还有许多其他库提供相同的功能。 谢谢!!

首先补充:

implementation androidx.swiperefreshlayout:swiperefreshlayout:1.1.0

到你的gradle 文件

XML文件

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/refreshLayout"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">

//Add here your views
// I've got a RecyclerView so for what I need height is 0dp

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

主要活动

 override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState)
    setContentView(activity_main)

    /* you probably have a few 
    code lines here*/
    initRefreshListener()
}
.
.
.
  private fun initRefreshListener() {

    val swipeRefreshLayout = findViewById<SwipeRefreshLayout>(R.id.refreshLayout)

    swipeRefreshLayout.setOnRefreshListener {

        Toast.makeText(this, "Refreshed", Toast.LENGTH_SHORT)
            .show() // totally optional
        // call API or what have you here
        swipeRefreshLayout.isRefreshing = false
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM