onunix 2023-03-07 23:10 采纳率: 81.2%
浏览 27
已结题

请问layout_constraintTop_toBottomO失效的原因


<?xml version="1.0" encoding="utf-8"?>
<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的顶部在同一高度)

  • 写回答

3条回答 默认 最新

  • 「已注销」 2023-03-07 23:16
    关注

    “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>
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月16日
  • 已采纳回答 3月8日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能