Android 带有进度指示器和动画的 RecyclerView

Android RecyclerView with progress indicator and animation

在 Material 设计指南中有一种模式可以一次加载和显示所有内容。

Link

如何使用RecyclerView实现?

您只需切换进度条和回收视图的可见性即可。

在您的布局中,

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
      <ProgressBar
            android:id="@+id/progress_bar"
            style="?android:progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            />
</FrameLayout>

根据上面的布局,在您的数据准备好之前,进度条显示在屏幕上。数据准备就绪后,您可以像这样切换可见性。

mRecyclerAdapter.setData(mData); // need to implement setter method for data in adapter
mRecyclerAdapter.notifyDataSetChanged();
mRecyclerView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);

希望对你有用。