在两个 Activity 之间创建一个进度条(没有 %),直到加载第二个 Activity 的内容

Create a Progress Bar (without %) between two Activities, until load the content of the Second Activity

我有一个带有按钮的 Main Activity,按下该按钮会打开第二个 Activity。第二个 Activity 将大量数据从 Firebase 加载到 RecyclerView 需要一些时间。当我点击 Main Activity 按钮时,我想打开一个带有进度条的页面(不显示百分比),只有当第二个 Activity 完全加载时,进度条才会关闭并显示第二个 Activity 的内容。做这个的最好方式是什么?任何的想法?谢谢

当您在 onCreate 方法中切换第二个活动时,如果您以编程方式实现进度条,请在实例化并将其添加到视图层次结构后将其设置为无限。然后,当您的数据在后台完成时,只需使用 View.GONE 属性隐藏假设您使用 Java 和垂直线性布局。

ProgressBar progressBar = new ProgressBar(this);
progressBar.setIndeterminate(true);
yourLinearLayout.addView(progressBar);
...
// Once your data has been loaded hide the progress bar
progressBar.setVisibility(View.GONE);
// Or remove it
yourLinearLayout.removeView(progressBar);

在xml布局文件中使用ProgressBar(在需要显示的fragment/activity处),像这样

    <RelativeLayout
        android:id="@+id/progressLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />
   </RelativeLayout>

并在关联的 activity 文件中,将可见性设置为 GONE。 在调用方法加载数据的地方执行此操作。

progressLayout.visibility = View.GONE

如果您可以将那部分代码添加到您的问题中,那么帮助会更容易。