如何在两个视图之间对齐底部并同时将顶部与父视图对齐?
how to align bottom between two view and align top to parent at the same time?
我试图在两个视图之间对齐底部并将它们与父视图的顶部对齐。当他们中的任何一个比另一个高时,它就会失败。似乎 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>
实际:
预计:
使用verticalBias
属性设置右header在底部,否则,它将位于parent顶部和左侧底部的中心。
设置 verticalBias
= 0(与顶部对齐)或 1(与底部对齐)。
将其包裹在 wrap_content
ConstraintLayout
中并将两个视图对齐到父视图的底部。这是一种方法
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/leftText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/rightText"
app:layout_constraintHorizontal_weight="3"
app:layout_constraintStart_toStartOf="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="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/leftText"
tools:text="RightHeader RightHeader RightHeader RightHeader" />
</androidx.constraintlayout.widget.ConstraintLayout>
将两个视图的顶部连接到父视图并将两个视图中的每个视图的底部相互连接,然后使两个文本中的垂直偏差等于一个
<?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>
我试图在两个视图之间对齐底部并将它们与父视图的顶部对齐。当他们中的任何一个比另一个高时,它就会失败。似乎 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>
实际:
预计:
使用verticalBias
属性设置右header在底部,否则,它将位于parent顶部和左侧底部的中心。
设置 verticalBias
= 0(与顶部对齐)或 1(与底部对齐)。
将其包裹在 wrap_content
ConstraintLayout
中并将两个视图对齐到父视图的底部。这是一种方法
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/leftText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/rightText"
app:layout_constraintHorizontal_weight="3"
app:layout_constraintStart_toStartOf="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="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/leftText"
tools:text="RightHeader RightHeader RightHeader RightHeader" />
</androidx.constraintlayout.widget.ConstraintLayout>
将两个视图的顶部连接到父视图并将两个视图中的每个视图的底部相互连接,然后使两个文本中的垂直偏差等于一个
<?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>