我在将 2 个视图放置在屏幕中央时遇到了 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/title”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:text=“Title”
android:textAppearance=“@style/Title1"
app:layout_constraintBottom_toTopOf=“@id/content”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toTopOf=“parent”
app:layout_constraintVertical_chainStyle=“packed” />
<EditText
android:id=“@+id/content”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:inputType=“text|textMultiLine|textNoSuggestions”
android:textAppearance=“@style/Title4"
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toBottomOf=“@id/title”
tools:text=“body\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\nbody\n” />
</androidx.constraintlayout.widget.ConstraintLayout>