我通过链创建了两行ImageButtons,并使用打包样式来缩小两行之间的间隙。但是,顶部和底部的整个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停留在它们现在所处的位置,因此按钮与布局的顶部和底部边缘之间存在间隙。我尝试使用垂直偏差缩小第二个图像中的间隙,但是你可以看到它只适用于顶行按钮而不是底行上的按钮。
答案 0 :(得分:1)
所以,问题是“为什么我的ConstraintLayout如此之高?”如果您可以使用{{1}}的更高版本(1.1.0-beta3是最新版本),则此问题将消失。如果您无法使用测试版,那么可以采用解决方法,但升级是最佳解决方案。如果您不能使用测试版,请退回。