0

我通过链创建了两行 ImageButton,并使用打包样式来缩小两行之间的间隙。然而,顶部和底部的整个 ImageButtons 行周围有很多额外的空间。

在此处输入图像描述

当我尝试在顶行按钮上使用 layout_constraintVertical_bias="0.1" 并在底行按钮上使用 layout_constraintVertical_bias="0.9" 来消除间隙时,它只会将行向上移动到布局的顶部。我知道链约束细节应该在父视图中,但是无论如何让链的孩子也适应偏差?我知道这可以通过将宽度更改为 0dp 来完成,但是当我这样做时,由于按钮数量不均匀,底部的图像变得比顶部的图像更宽。

在此处输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content">

    <ImageButton
        android:id="@+id/button1"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button4"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button2"
        app:layout_constraintVertical_chainStyle="packed"/>

    <ImageButton
        android:id="@+id/button2"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button4"
        app:layout_constraintLeft_toRightOf="@+id/button1"
        app:layout_constraintRight_toLeftOf="@id/button3"
        app:layout_constraintVertical_bias="1"/>

    <ImageButton
        android:id="@+id/button3"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button5"
        app:layout_constraintLeft_toRightOf="@id/button2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintVertical_chainStyle="packed"/>

    <ImageButton
        android:id="@+id/button4"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/button1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button5"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <ImageButton
        android:id="@+id/button5"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/button3"
        app:layout_constraintLeft_toRightOf="@id/button4"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>

编辑:

这就是我想要在下面完成的。我基本上希望箭头向上推到红线,而 ImageButtons 保持在它们现在所在的位置,因此按钮与布局的顶部和底部边缘之间存在间隙。我尝试使用垂直偏差缩小第二张图像中的间隙,但正如您所见,它仅适用于顶行按钮,不适用于底行按钮。

在此处输入图像描述

4

1 回答 1

1

所以,问题真的是“为什么我的 ConstraintLayout 这么高?” 如果你可以使用更高版本ConstraintLayout(1.1.0-beta3 是最新的),这个问题就会消失。如果您不能使用 beta 版本,有一个变通方法,但升级是最好的解决方案。如果您不能使用 beta 版本,请回复。

于 2017-12-04T03:00:16.860 回答