gpt4 book ai didi

android - 约束布局中的动态高度对齐

转载 作者:行者123 更新时间:2023-12-04 11:30:53 27 4
gpt4 key购买 nike

我有 3 个 TextView ,其中的文本可以动态更改,我需要使它们彼此相等,它们的高度大于该高度并占据所有位置。我正在尝试使用障碍但没有得到积极的结果,我也尝试将所有 textviews 高度设置为 0dp 但所有 textviews 然后都消失了,我可以为一个 textview wrap_content 和另一个 0dp 设置高度,但它们将仅在第一个 TextView 。当我使用线性布局时,我做到了,但是使用约束布局我不明白怎么做。
enter image description here

xml:

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

<TextView
android:id="@+id/label_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:fontFamily="@font/gothic_bold"
android:gravity="center"
android:text="test 1"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@+id/label_zone2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coefficient_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone1"
app:layout_constraintStart_toStartOf="@+id/label_zone1"
app:layout_constraintTop_toBottomOf="@+id/label_zone1" />

<TextView
android:id="@+id/consumption_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:fontFamily="@font/gothic"
android:gravity="center|center_vertical"
android:text="1234567"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone1"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone1"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<TextView
android:id="@+id/label_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:fontFamily="@font/gothic_bold"
android:gravity="center"
android:text="test 2"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@+id/label_zone3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/label_zone1"
app:layout_constraintTop_toTopOf="@+id/label_zone1" />

<TextView
android:id="@+id/coefficient_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone2"
app:layout_constraintStart_toStartOf="@+id/label_zone2"
app:layout_constraintTop_toBottomOf="@+id/label_zone2" />

<TextView
android:id="@+id/consumption_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:fontFamily="@font/gothic"
android:gravity="center|center_vertical"
android:text="1234567"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone2"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone2"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<TextView
android:id="@+id/label_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:fontFamily="@font/gothic_bold"
android:gravity="center"
android:text="test 3"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/label_zone2"
app:layout_constraintTop_toTopOf="@+id/label_zone2" />

<TextView
android:id="@+id/coefficient_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone3"
app:layout_constraintStart_toStartOf="@+id/label_zone3"
app:layout_constraintTop_toBottomOf="@+id/label_zone3" />

<TextView
android:id="@+id/consumption_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:fontFamily="@font/gothic"
android:gravity="center|center_vertical"
android:text="12345678"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone3"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone3"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="coefficient_zone1,coefficient_zone2,coefficient_zone3" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3" />

<TextView
android:id="@+id/label_calculated_indicators"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="@font/gothic_bold"
android:gravity="center"
android:text="title title title title"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone3"
app:layout_constraintStart_toStartOf="@+id/label_zone1"
app:layout_constraintTop_toBottomOf="@+id/consumption_zone1" />

</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

正如 Nikos Hidalgo 在对您的问题的评论中所说,这是 Stack Overflow 上提出的一个常见问题。我遇到了四种方法来实现一组 View 的共同宽度和/或共同高度。不幸的是,没有一个是理想的。

这是一个屏幕截图,显示了达到共同维度的四种方法中的三种。此屏幕的 XML 在本文末尾。

enter image description here

嵌入式线性布局

这可能是最简单的方法。将 TextViews 放置在水平 LinearLayout 中,将它们的高度设置为 MATCH_PARENT。将 LinearLayout 的高度设置为 WRAP_CONTENT,一切都会解决。这种方式的好处是它的简单性。负面因素包括嵌套布局的开销以及 LinearLayout 内的任何 View 都无法连接到 LinearLayout 外的任何 View - 它们变成了一个孤岛。

不可见的 View

这可能是最复杂的做事方式,但根据布局可能没问题。设置障碍以调整一组 View 的高度的基本问题是障碍的位置取决于 View 的高度,而 View 的高度取决于障碍的位置。这是一个引用难题,不适用于当前版本的 ConstraintLayout。

不可见 View 解决方案是将要调整高度的 View 复制为不可见 View 。为这些不可见的 View 设置顶部和底部屏障。将可见 View 的高度设置为 MATCH_CONSTRAINTS 并将顶部连接到顶部屏障,将底部连接到底部屏障。

这种方法的好处是它是完全平坦的,并且只涉及 ConstraintLayout。缺点是它会根据要调整的 View 数量、复杂性以及复杂性所带来的一切来增加 View 计数。

约束布局大小助手

第三种方法是使用自定义 ConstraintHelper 来更改 View 的高度。自定义 ConstraintHelper 像任何其他 View 一样被插入到布局的 XML 中,并用于引用要调整的 View 。

这种方法的好处是所有更改都保存在 XML 中。不利的是,必须引用和维护自定义类。

监听器更新宽度/高度

最后一种方法是使用全局布局监听器、布局监听器等对高度调整进行自定义编码。这类似于 ConstraintHelper 方法,但存在于 XML 之外并且可能没有很好地封装。

也可以使用自定义 ConstraintLayout 或自定义 TextView 编写自定义 View 以将 View 高度设置为最大高度。

示例布局

        <TextView
android:id="@+id/textView2_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Embedded LinearLayout"
app:layout_constraintBottom_toTopOf="@+id/layout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:ignore="HardcodedText" />

<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@android:color/holo_blue_bright"
app:layout_constraintBottom_toTopOf="@id/textView3_0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2_0">

<TextView
android:id="@+id/textView2_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView2_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView2_3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="@android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
tools:ignore="HardcodedText" />
</LinearLayout>

<TextView
android:id="@+id/textView3_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Invisible Views"
app:layout_constraintBottom_toTopOf="@id/textView3_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout2"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView3_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/textView3_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView3_2"
tools:visibility="invisible"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView3_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@id/textView5_0"
app:layout_constraintEnd_toStartOf="@+id/textView3_3"
app:layout_constraintStart_toEndOf="@+id/textView3_1"
app:layout_constraintTop_toBottomOf="@id/textView3_0"
tools:visibility="invisible"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView3_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3_2"
app:layout_constraintTop_toTopOf="@+id/textView3_2"
tools:visibility="invisible"
tools:ignore="HardcodedText" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrierTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="textView3_1,textView3_2,textView3_3" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrierBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="textView3_1,textView3_2,textView3_3" />

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
app:layout_constraintBottom_toTopOf="@id/barrierBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrierTop" />

<TextView
android:id="@+id/textView4_1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@id/barrierBottom"
app:layout_constraintEnd_toStartOf="@+id/textView4_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/barrierTop"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView4_2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@id/barrierBottom"
app:layout_constraintEnd_toStartOf="@+id/textView4_3"
app:layout_constraintStart_toEndOf="@+id/textView4_1"
app:layout_constraintTop_toBottomOf="@+id/barrierTop"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView4_3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintBottom_toTopOf="@id/barrierBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView4_2"
app:layout_constraintTop_toBottomOf="@+id/barrierTop"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView5_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="ConstraintLayout Size Helper"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrierBottom"
tools:ignore="HardcodedText" />

<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
app:layout_constraintBottom_toBottomOf="@id/textView5_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/textView5_1" />

<TextView
android:id="@+id/textView5_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/textView5_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView5_2"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView5_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/textView5_3"
app:layout_constraintStart_toEndOf="@+id/textView5_1"
app:layout_constraintTop_toBottomOf="@+id/textView5_0"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView5_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="@android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView5_2"
app:layout_constraintTop_toTopOf="@+id/textView5_2"
tools:ignore="HardcodedText" />

<com.example.constraintsizehelper.ConstraintSizeHelper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="textView5_1,textView5_2,textView5_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:setCommonWidth="true"
app:setCommonHeight="true"
tools:layout_height="120dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

这是使用 Constraint Size Helper 类(未提供)的布局的简化版本:

enter image description here

及其 XML:

activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/label_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 1"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@+id/label_zone2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coefficient_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone1"
app:layout_constraintStart_toStartOf="@+id/label_zone1"
app:layout_constraintTop_toBottomOf="@+id/label_zone1" />

<TextView
android:id="@+id/consumption_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:gravity="center|center_vertical"
android:text="0"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone1"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone1"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<TextView
android:id="@+id/label_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 2"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@+id/label_zone3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/label_zone1"
app:layout_constraintTop_toTopOf="@+id/label_zone1" />

<TextView
android:id="@+id/coefficient_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone2"
app:layout_constraintStart_toStartOf="@+id/label_zone2"
app:layout_constraintTop_toBottomOf="@+id/label_zone2" />

<TextView
android:id="@+id/consumption_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:gravity="center|center_vertical"
android:text="12345678"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone2"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone2"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<TextView
android:id="@+id/label_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:gravity="center"
android:text="test 3"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/label_zone2"
app:layout_constraintTop_toTopOf="@+id/label_zone2" />

<TextView
android:id="@+id/coefficient_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone3"
app:layout_constraintStart_toStartOf="@+id/label_zone3"
app:layout_constraintTop_toBottomOf="@+id/label_zone3" />

<TextView
android:id="@+id/consumption_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/input_border"
android:gravity="center|center_vertical"
android:text="1234567890"
android:textColor="@color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="@+id/barrier2"
app:layout_constraintEnd_toEndOf="@+id/coefficient_zone3"
app:layout_constraintStart_toStartOf="@+id/coefficient_zone3"
app:layout_constraintTop_toBottomOf="@+id/barrier" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="coefficient_zone1,coefficient_zone2,coefficient_zone3" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3" />

<TextView
android:id="@+id/label_calculated_indicators"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="title title title title"
android:textAllCaps="true"
android:textColor="@color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="@+id/label_zone3"
app:layout_constraintStart_toStartOf="@+id/label_zone1"
app:layout_constraintTop_toBottomOf="@+id/consumption_zone1" />

<com.example.myapplication.ConstraintSizeHelper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_height="120dp"
app:setCommonWidth="false"
app:setCommonHeight="true"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3"/>

</androidx.constraintlayout.widget.ConstraintLayout>

关于android - 约束布局中的动态高度对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60337281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com