Ответ 1
- Создайте
horizontal chain
с помощьюtopLeftText
иtopRightText
, установите стиль цепочки наpacked
, чтобы центрировать текст по горизонтали, также добавьтеend margin
кtopLeftText
, чтобы обеспечить некоторое горизонтальное пространство между текстами - установите
top constraint
topLeftText
наtop
topRightText
, чтобы выровнять текст сверху. - Создайте
vertical chain
с помощьюtopRightText
иbottomText
, установите стиль цепочки наpacked
, чтобы центрировать текст по вертикали, добавьтеtop margin
к bottomText, чтобы обеспечить некоторое вертикальное пространство между текстами. - Добавьте поле
constraint layout
, чтобы текст не касался краев.
Скриншот
XML
<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"
android:layout_margin="16dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/topLeftText"
android:layout_width="182dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@+id/topRightText"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/topRightText"
android:text="Test test test test test test test test test test" />
<TextView
android:id="@+id/topRightText"
android:layout_width="182dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/bottomText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/topLeftText"
app:layout_constraintTop_toTopOf="parent"
android:text="Test test test test test test test test test test test test test test test test test test test test" />
<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="topLeftText,topRightText" />
<TextView
android:id="@+id/bottomText"
android:layout_width="379dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Test test test test test test test test test test test test test test test test test test test test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/topRightText" />
</androidx.constraintlayout.widget.ConstraintLayout>