gpt4 book ai didi

android - 如何在两个 View 之间对齐底部并同时将顶部对齐到父级?

转载 作者:行者123 更新时间:2023-12-04 08:21:28 24 4
gpt4 key购买 nike

我试图在两个 View 之间对齐底部并将它们对齐到父 View 的顶部。当他们中的任何一个比另一个高时,它就会失败。好像app:layout_constraintBottom_toBottomOf="@id/rightText"app:layout_constraintTop_toTopOf="parent"相互矛盾。

<?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/leftText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
app:layout_constraintBottom_toBottomOf="@id/rightText"
app:layout_constraintEnd_toStartOf="@id/rightText"
app:layout_constraintHorizontal_weight="3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Header Header Header Header Header Header Header Header" />

<TextView
android:id="@+id/rightText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/leftText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/leftText"
app:layout_constraintTop_toTopOf="parent"
tools:text="RightHeader RightHeader RightHeader RightHeader" />

</androidx.constraintlayout.widget.ConstraintLayout>
实际的:
enter image description here
预计:
enter image description here
enter image description here

最佳答案

将两个 View 的顶部连接到 parent 并将两个 View 中的每一个的底部相互连接,然后使两个文本中的垂直偏差等于 1

<?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/leftText"
style="@style/TextAppearance.Body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
app:layout_constraintBottom_toBottomOf="@+id/rightText"
app:layout_constraintEnd_toStartOf="@id/rightText"
app:layout_constraintHorizontal_weight="3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:text="Header asd da asd sda ads dsa dsa ads sda dsa das dsa das dsa dsda s dssdanksadasdjadsasbdjadskbjsdkbajdsbjasdkbjkadsbjkadsbjkasdbjkaskbjasdbjkasdbjkasdbjkasdbjkasdkbjasbjkasdkbjasdbjkasdbjkHeader Header Header Header Header Header Header" />

<TextView
android:id="@+id/rightText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/leftText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/leftText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:text="RightHeader RightHeader RightHeader RightHeader" />

</androidx.constraintlayout.widget.ConstraintLayout>

关于android - 如何在两个 View 之间对齐底部并同时将顶部对齐到父级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65476530/

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