【问题标题】:Android Progress bar shows behind Page contentAndroid 进度条显示在页面内容后面
【发布时间】:2021-11-08 13:52:06
【问题描述】:

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

<?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>

【问题讨论】:

    标签: android android-layout android-progressbar android-loader


    【解决方案1】:

    你试过了吗:

    
    <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"
    

    可能也可以

    【讨论】:

      【解决方案2】:

      您可能想了解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 内的底部

      【讨论】:

        猜你喜欢
        • 2013-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-27
        • 1970-01-01
        相关资源
        最近更新 更多