Android 进度条显示在页面内容后面

Android Progress bar shows behind Page content

我想在 API 通话期间在屏幕上显示进度条。如下所示创建了 API,但一旦它可见,它就会显示在 buttons/text 字段后面。如果屏幕上没有项目,则它是完全可见的。如果有按钮或按钮后面显示的东西。所以我看不到它。如果实施有任何问题,请告诉我。

<?xml version="1.0" encoding="utf-8"?>
        <ScrollView 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"
            android:fillViewport="true"
      >
    <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/window_layout"
                android:background="@color/white"
                >
            <FrameLayout
                android:id="@+id/linearLayout5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:id="@+id/progress_linear"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical">
                <ProgressBar
                    style="?android:attr/progressBarStyleInverse"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:indeterminate="true"
                    android:theme="@style/ProgressBarTheme"
                    android:id="@+id/progress"
                    android:layout_gravity="center" />
                </LinearLayout>
            <LinearLayout
                android:orientation="vertical"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:ignore="MissingConstraints">
                 <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dip"
                    android:text="@string/txt_setup"
                    android:layout_marginBottom="16dp"
                    /><RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="42dp"
                    android:layout_marginTop="8dp"
                    android:id="@+id/spinner_layout"
                    android:background="@drawable/spinner_back"\>
                     <Spinner
                        android:id="@+id/spinner"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:dropDownWidth="match_parent"
                        android:dropDownVerticalOffset="40dp"
                        android:background="@android:color/transparent"
                        android:spinnerMode="dropdown" />
                         <ImageView
                        android:id="@+id/spinner_arr"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/ic__2_web_icons_ic_caretdown_gra"/>
                </RelativeLayout>
            </LinearLayout>
            </FrameLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
        </ScrollView>

你试过了吗:


<LinearLayout
    android:id="@+id/progress_linear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
+   android:elevation="1dp">
    <ProgressBar
         style="?android:attr/progressBarStyleInverse"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:indeterminate="true"
         android:theme="@style/ProgressBarTheme"
         android:id="@+id/progress"
         android:layout_gravity="center" />
</LinearLayout>

这可能会将此布局置于最前面

android:translationZ="1dp"

也可能工作

您可能想了解 FrameLayout 的工作原理,但通常对于 FrameLayout 中的每个子视图,位于层次结构底部的子视图将显示在顶部。因此,对于您的情况,您需要进行如下更改

   <FrameLayout
                    android:id="@+id/linearLayout5"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                   
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:ignore="MissingConstraints">
                     <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="24dip"
                        android:text="@string/txt_setup"
                        android:layout_marginBottom="16dp"
                        /><RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="42dp"
                        android:layout_marginTop="8dp"
                        android:id="@+id/spinner_layout"
                        android:background="@drawable/spinner_back"\>
                         <Spinner
                            android:id="@+id/spinner"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:dropDownWidth="match_parent"
                            android:dropDownVerticalOffset="40dp"
                            android:background="@android:color/transparent"
                            android:spinnerMode="dropdown" />
                             <ImageView
                            android:id="@+id/spinner_arr"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:src="@drawable/ic__2_web_icons_ic_caretdown_gra"/>
                    </RelativeLayout>
                </LinearLayout>

               <LinearLayout
                        android:id="@+id/progress_linear"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:orientation="vertical">
                    <ProgressBar
                        style="?android:attr/progressBarStyleInverse"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:indeterminate="true"
                        android:theme="@style/ProgressBarTheme"
                        android:id="@+id/progress"
                        android:layout_gravity="center" />
                    </LinearLayout>

                </FrameLayout>

请注意我是如何将您的 progress_linear LinearLayout 移动到 FrameLayout

中的底部的