Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 约束中带有障碍物的链_Android_Android Constraintlayout - Fatal编程技术网

Android 约束中带有障碍物的链

Android 约束中带有障碍物的链,android,android-constraintlayout,Android,Android Constraintlayout,我想使用无嵌套的ConstraintLayout实现下面的布局 布局需要一个屏障,因为不能保证哪个textview更高。它还需要一个链条,因为所有东西都需要居中。问题是,我找不到一种方法使连锁店与障碍物一起工作 以下是迄今为止我所掌握的内容,这些内容将正确布局,但不会居中: <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

我想使用无嵌套的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\u height=“包装内容” android:layout_gravity=“center”



您是否尝试将左上角文本视图的顶部约束到右上角文本视图的顶部。然后将右上角和右下角的文本视图约束为BarrierId解决问题,如果是,如何解决?我目前面临着一个类似的问题,我能想到的唯一解决方案是使用嵌套布局。哪种方法与使用ConstraintLayout(保持层次结构平坦)相矛盾。您找到解决方法了吗?您面临的问题是无法将所有内容垂直居中吗?如果是这样的话,也许你可以试着用一条水平的指导线来代替屏障?@treyworm我使用了嵌套的布局。由于这个问题仍然没有答案,我认为如果不改变ConstraintLayout,这可能是不可能实现的。
<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">