Android 原生下拉加载圈

2021-03-24  本文已影响0人  wenju

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);
            }
        });
上一篇下一篇

猜你喜欢

热点阅读