Android 约束布局中心垂直放置

Android 约束布局中心垂直放置,android,layout,constraints,Android,Layout,Constraints,我使用链接在视图中垂直居中放置两个输入布局。在这两个输入布局的顶部,我还有一个图像视图和一个文本视图。如果视图有足够的空间,我只希望此输入布局中心 现在,输入布局始终居中,文本覆盖图像 在ios中,我会使用约束优先级来执行此操作,但看起来这对于约束布局还不可用 我现在有什么 我想要的是 编辑 对不起,我应该添加文本:) 我也不知道怎么做!但是我找到了一个和你想要的很接近的东西 我所做的是创建一个固定在特定高度的指南元素,当视图位于其下方时,该元素使我的视图看起来垂直居中。对于不同尺寸的手机,

我使用链接在视图中垂直居中放置两个输入布局。在这两个输入布局的顶部,我还有一个图像视图和一个文本视图。如果视图有足够的空间,我只希望此输入布局中心

现在,输入布局始终居中,文本覆盖图像

在ios中,我会使用约束优先级来执行此操作,但看起来这对于约束布局还不可用

我现在有什么

我想要的是

编辑

对不起,我应该添加文本:)


我也不知道怎么做!但是我找到了一个和你想要的很接近的东西

我所做的是创建一个固定在特定高度的
指南
元素,当视图位于其下方时,该元素使我的视图看起来垂直居中。对于不同尺寸的手机,这可能会被关闭一个或十个像素,但它不应该太坏

然后我创建了一个
屏障
,它引用了指南和我想“闪避”的另一个视图。我会根据这个障碍来定位我的其他元素

我的XML:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/rect"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_marginTop="16dp"
        android:background="#fac"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.34"/>

    <android.support.constraint.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="rect,guideline"/>

    <View
        android:id="@+id/first"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        android:background="#caf"
        app:layout_constraintTop_toBottomOf="@id/barrier"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <View
        android:id="@+id/second"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        android:background="#caf"
        app:layout_constraintTop_toBottomOf="@+id/first"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>

使用短的
rect
视图时,两个中间视图垂直居中,使用高的
rect
视图时,两个中间视图向下推:


请分享版式的文本部分,这将有助于获得答案。这很好!希望他们能改进这种想法。
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/rect"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_marginTop="16dp"
        android:background="#fac"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.34"/>

    <android.support.constraint.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="rect,guideline"/>

    <View
        android:id="@+id/first"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        android:background="#caf"
        app:layout_constraintTop_toBottomOf="@id/barrier"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <View
        android:id="@+id/second"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        android:background="#caf"
        app:layout_constraintTop_toBottomOf="@+id/first"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>