美文网首页
Android 原生下拉加载圈

Android 原生下拉加载圈

作者: wenju | 来源:发表于2021-03-24 15:32 被阅读0次

1.xml布局

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        material:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/downloadsCompletedList"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/downloadsCompletedFooter"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="10dp" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

2.处理刷新逻辑代码

        final SwipeRefreshLayout srl = rootView.findViewById(R.id.swipe_refresh_layout);//获取 SwipeRefreshLayout 实例
        srl.setColorSchemeResources(R.color.colorPrimary);//设置刷新进度条颜色
        srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                downloaddata.clear();
                downloaddata.addAll(DownloadAriaManager.getUseDownloadFrame().getAllCompleteTask());
                adapter.notifyDataSetChanged();
                
                //刷新完成,取消动画效果
                srl.setRefreshing(false);
            }
        });

相关文章

网友评论

      本文标题:Android 原生下拉加载圈

      本文链接:https://www.haomeiwen.com/subject/uffkcltx.html