我不知道
为什么?
这种情况正在发生,也许这确实是
1.1.0-beta5
但是
应用于
background
视图由三个按钮组成的链继承,因为该链约束到
出身背景
。如果删除这些边距,“间隙”会突然消失:
<View
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginTop="16dp"
android:background="@drawable/background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
当然,您的设计可能需要这些边距。您可以通过将原始边距恢复到
出身背景
查看并将链锚定到父对象而不是背景。也就是说,更改
app:layout_constraintStart_toStartOf
属性打开
button1
到
"parent"
,并更改
app:layout_constraintEnd_toEndOf
属性打开
button3
到
“父级”
:
最后一个难题是更改
链条
模仿旧的行为。之前您有
出身背景
查看方式
48dp
利润率,以及
4dp
页边距。因此,将链边距设置为
52dp
而不是
4dp
要包括背景的48dp:
我的完整XML:
<?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="match_parent">
<View
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginTop="16dp"
android:layout_marginStart="48dp"
android:layout_marginEnd="48dp"
android:background="@drawable/background"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="24dp"
android:layout_marginStart="52dp"
android:gravity="center"
android:text="Button1"
android:background="@drawable/button_background"
app:layout_constraintTop_toTopOf="@id/background"
app:layout_constraintBottom_toBottomOf="@id/background"
app:layout_constraintEnd_toStartOf="@id/button2"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="24dp"
android:gravity="center"
android:text="Button2"
android:background="@drawable/button_background"
app:layout_constraintTop_toTopOf="@id/background"
app:layout_constraintBottom_toBottomOf="@id/background"
app:layout_constraintEnd_toStartOf="@id/button3"
app:layout_constraintStart_toEndOf="@id/button1"/>
<TextView
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="24dp"
android:layout_marginEnd="52dp"
android:gravity="center"
android:text="Button3"
android:background="@drawable/button_background"
app:layout_constraintTop_toTopOf="@id/background"
app:layout_constraintBottom_toBottomOf="@id/background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/button2"/>
</android.support.constraint.ConstraintLayout>