【问题标题】:Constraint-Layout alpha7 ConstraintCenterX/Y attribute missingConstraint-Layout alpha7 ConstraintCenterX/Y 属性缺失
【发布时间】:2017-01-20 21:21:11
【问题描述】:

我刚刚从com.android.support.constraint:constraint-layout:1.0.0-alpha5 更新为com.android.support.constraint:constraint-layout:1.0.0-alpha7,但缺少layout_constraintCenterX_toCenterXlayout_constraintCenterY_toCenterY。他们是否更改了名称,或者是否可以将两个视图居中。

编辑 - 我确实在这里看到了他们的发行说明 http://tools.android.com/recent/constraintlayout-alpha7available 他们只是说它已被弃用。但我想要一个解决方案(替代方案)。

【问题讨论】:

    标签: android android-constraintlayout


    【解决方案1】:

    如果您想将 B 的中心与 A 的中心对齐,那么您应该让 B 将其左右与 A 的左右对齐。

    这是一个示例 - text2 将位于 text1 的下方和中心:

    <TextView
        android:id="@+id/text1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:labelFor="@+id/text2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />
    
    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="@+id/text1"
        app:layout_constraintRight_toRightOf="@+id/text1"
        app:layout_constraintTop_toBottomOf="@+id/text1" />
    

    【讨论】:

    • 乔伊怎么说。请注意,centerX_toCenterX 基本上只是一个快捷方式——在内部它执行 left_toLeftOf 和 right_toRightOf。中心Y相同。
    【解决方案2】:

    是的,它在 ConstraintLayout-alpha 7 here的发行说明中

    【讨论】:

      【解决方案3】:

      支持 RTL 的简单解决方案

      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias=".5"
      

      不支持 RTL

      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintHorizontal_bias=".5"
      

      您可以根据需要删除 app:layout_constraintHorizo​​ntal_bias

      我还在这里报告了 RTL 错误:

      Link 1

      Link 2

      【讨论】:

        猜你喜欢
        • 2018-03-08
        • 2021-01-20
        • 2016-11-22
        • 2018-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-17
        相关资源
        最近更新 更多