【发布时间】:2021-06-29 00:45:16
【问题描述】:
我想在 RecyclerView 的列表结束后显示 ProgressBar。当前,当我向下滚动显示最后一项的 ProgressBar 并且当新帖子获取最后一项时消失了。 在谷歌上搜索但找不到答案,我是新开发者,请帮助
这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view">
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressbar"
android:layout_below="@+id/recycler_view"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
tools:ignore="NotSibling" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
进度条:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (!recyclerView.canScrollVertically(1) && dy > 0)
{ //check for scroll down
visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
if (!loading){
progressBar.setVisibility(View.VISIBLE);
loading = true;
yourURL = baseURL + baseModel + "&page=" + pageNo++;
getRetrofit();
}
}
}
【问题讨论】:
标签: android list listview android-recyclerview progress-bar