<androidx.constraintlayout.widget.ConstraintLayout 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"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/aa"
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:id="@+id/bb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@id/aa"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
androidx.constraintlayout.widget.ConstraintLayout>
请问这里,这句app:layout_constraintTop_toBottomOf="@id/aa"为什么会失效,我本意是希望使用这句,使得bb在aa的下方,但实际效果,aa和bb顶部对齐(aa的顶部和bb的顶部在同一高度)
“Devil组”引证GPT后的撰写:
如下所示:
<androidx.constraintlayout.widget.ConstraintLayout 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"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/aa"
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:id="@+id/bb"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@id/aa"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/aa"
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@id/bb"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:id="@+id/bb"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/aa" />
</androidx.constraintlayout.widget.ConstraintLayout>
给两个控件捆绑起来再与父布局绑定
不知道你这个问题是否已经解决, 如果还没有解决的话: