请问layout_constraintTop_toBottomO失效的原因



<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后的撰写:

  • LinearLayoutCompat 控件的高度设置为 45dp,因此,它的底部将位于屏幕顶部的 45dp 下方。然而,TextView 控件的高度设置为 match_parent,这意味着它将填充整个父容器的高度,包括 LinearLayoutCompat 控件的高度。
  • 因此,将 app:layout_constraintTop_toBottomOf="@id/aa" 应用于 TextView 控件将使其顶部与 LinearLayoutCompat 控件的底部对齐,而不是 LinearLayoutCompat 控件的顶部。要将 TextView 控件放置在 LinearLayoutCompat 控件下方,请将 LinearLayoutCompat 控件的底部约束与 TextView 控件的顶部约束相连

如下所示:

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

给两个控件捆绑起来再与父布局绑定

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^