【发布时间】:2021-05-04 00:12:17
【问题描述】:
我正在尝试在Button 之上添加一个ProgressBar(两者都在ConstraintLayout 内)。
<Button
android:id="@+id/sign_in_button"
android:layout_width="280dp"
android:layout_height="75dp"
android:layout_marginBottom="75dp"
android:layout_marginTop="50dp"
android:text="@string/sign_in"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
app:layout_constraintVertical_bias="0.0"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/sign_in_button"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/sign_in_button"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.5"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="@+id/sign_in_button"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="@+id/sign_in_button"/>
但即使在onCreate 中的ProgressBar 上调用bringToFront 之后,它也始终停留在Button 后面。
ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.bringToFront();
【问题讨论】:
-
这太奇怪了,我试着玩一下你的布局,甚至颠倒了链条,这样进度条就限制在编辑文本上,按钮限制在进度条上,但按钮似乎始终位于进度条的顶部
-
你可以使用 FrameLayout 吗?试一试,知道在 FrameLayout 中,z-index 是由布局内的顺序给出的(所以 Button 1st,Progress 2nd)
-
你的密码编辑文本在哪里,因为我在没有应用程序的情况下检查了:layout_constraintTop_toBottomOf="@+id/passwordEditText" 我可以看到顶部的进度条你能提供密码编辑文本吗
标签: android android-layout android-constraintlayout