首页 > 解决方案 > 偏置属性被忽略

问题描述

我有一个简单的水平链视图布局,带有 spread_inside 链样式。当我尝试使用偏差属性将视图移动到所需位置时,我发现偏差属性被忽略了。

这是供参考的布局:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <View
        android:id="@+id/view_1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toStartOf="@id/view_2"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_2"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toStartOf="@id/view_3"
        app:layout_constraintStart_toEndOf="@id/view_1"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_3"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.2"
        app:layout_constraintStart_toEndOf="@id/view_2"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

在这里,我想使用 layout_constraintHorizo​​ntal_bias 属性将 view_3 移近 view_2。我怎样才能做到这一点?

标签: androidandroid-constraintlayoutconstraint-layout-chains

解决方案


如果您在视图中使用水平链,则水平偏置不起作用(因为您在同一轴上提供偏置,如果存在水平链,则垂直偏置将起作用,反之亦然);除非你想将它应用到你创建的链的头视图(这是水平链中最左边的视图和垂直链中最顶部的视图);这不是你的情况,在这里Also, the applied biasing on the head view of the chain only works if the selected chain style is packed. 因此,您应该尝试找到一些其他解决方法来实现您想要的 UI 并忽略使用 chain (here)

有关更多信息,请参阅:使用 ConstraintLayout 构建响应式 UI

希望我的回答对你有所帮助。


推荐阅读