我想使用没有嵌套的 ConstraintLayout 实现下面的布局。
布局需要一个屏障,因为不能保证哪个 textview 会更高。它还需要一条链,因为一切都需要居中。问题是我找不到一种方法来使链条与障碍一起工作。
这是我到目前为止的布局,但不会居中:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/topLeftText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
tools:text="Test test test test test test test test test test"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/topRightText"/>
<TextView
android:id="@+id/topRightText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
tools:text="Test test test test test test test test test test test test test test test test test test test test"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@+id/topLeftText"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.constraint.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="topLeftText,topRightText"
app:barrierDirection="bottom"/>
<TextView
android:id="@+id/bottomText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
tools:text="Test test test test test test test test test test test test test test test test test test test test"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/barrier"/>
</android.support.constraint.ConstraintLayout>
如果有人知道如何实现这一点,那将不胜感激!
最佳答案
我知道它很旧,但我认为要在没有嵌套的情况下做到这一点,您必须将顶级组件更改为这样的东西。
android:layout_height="wrap_content" android:layout_gravity="center"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
关于android - 在 ConstraintLayout 中使用障碍链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55699062/