我一直在android工作室使用constraintlayouts构建我的用户界面。然而,我有一个问题,我得到了一些神秘的额外利润底部的一个孩子约束,抛出了一切不协调。
正如您在这个gif中看到的,只要我将edittext约束到imageview,constraintlayout的底部就会出现一个很大的边距。我好像搞不懂为什么会这样。
因此,只要我将任何其他约束布局约束到不可靠的约束布局,所有的对齐都会出错,元素不再居中,如下面的gif所示。
下面是整个布局的代码(Dodgey表单的ID为“CreateTaskViewFormContainer”):
link to gist of code
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#E8ECEE"
tools:context="apps.cal.lonesafe.CreateTaskFragment.CreateTaskView">
<android.support.constraint.ConstraintLayout
android:id="@+id/createTaskViewFormContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="#ffffff"
android:elevation="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/createTaskViewTeamName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:elevation="2dp"
android:text="New Task"
android:textColor="#000000"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/createTaskViewLabelIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="32dp"
android:src="@drawable/ic_label_32dp"
app:layout_constraintBottom_toBottomOf="@+id/createTaskViewTaskNameEditText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/createTaskViewTaskNameEditText" />
<EditText
android:id="@+id/createTaskViewTaskNameEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:background="@drawable/edittext_alignment_background_grey"
android:elevation="2dp"
android:hint="Task Name"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/createTaskViewLabelIcon"
app:layout_constraintTop_toBottomOf="@+id/createTaskViewTeamName" />
<ImageView
android:id="@+id/createTaskViewClockIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_clock_32dp"
app:layout_constraintBottom_toBottomOf="@+id/createTaskViewTimePickerTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/createTaskViewTimePickerTextView" />
<TextView
android:id="@+id/createTaskViewTimePickerTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:background="@drawable/edittext_alignment_background_grey"
android:elevation="2dp"
android:text="00h 00m"
android:textColor="#94989a"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="@+id/createTaskViewTaskNameEditText"
app:layout_constraintStart_toEndOf="@+id/createTaskViewClockIcon"
app:layout_constraintTop_toBottomOf="@+id/createTaskViewTaskNameEditText" />
<Button
android:id="@+id/createTaskViewRecordMessageButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="32dp"
android:background="@drawable/button_blue_roundsquare"
android:text="Record Message"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/createTaskViewTimePickerTextView"
app:layout_constraintStart_toStartOf="@+id/createTaskViewClockIcon"
app:layout_constraintTop_toBottomOf="@+id/createTaskViewTimePickerTextView" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/createTaskViewTeamSettingsLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="#ffffff"
android:elevation="2dp"
app:layout_constraintBottom_toTopOf="@+id/createTaskViewPanicButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/createTaskViewStartButton">
<View
android:id="@+id/createTaskViewGuardianSettingsPinIconCentreView"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/createTaskViewGuardianSettingsFirstPinIcon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="16dp"
android:src="@drawable/ic_mic_32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/createTaskViewGuardianSettingsSecondPinIcon"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/createTaskViewGuardianSettingsSecondPinIcon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginEnd="11.5dp"
android:src="@drawable/ic_checkin_32dp"
app:layout_constraintBottom_toBottomOf="@+id/createTaskViewGuardianSettingsPinIconCentreView"
app:layout_constraintEnd_toStartOf="@+id/createTaskViewGuardianSettingsPinIconCentreView"
app:layout_constraintTop_toTopOf="@+id/createTaskViewGuardianSettingsPinIconCentreView" />
<ImageView
android:id="@+id/createTaskViewGuardianSettingsThirdPinIcon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginStart="11.5dp"
android:src="@drawable/ic_pin_32dp"
app:layout_constraintBottom_toBottomOf="@+id/createTaskViewGuardianSettingsPinIconCentreView"
app:layout_constraintStart_toEndOf="@+id/createTaskViewGuardianSettingsPinIconCentreView"
app:layout_constraintTop_toTopOf="@+id/createTaskViewGuardianSettingsPinIconCentreView" />
<ImageView
android:id="@+id/createTaskViewGuardianSettingsFifthPinIcon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginStart="24dp"
android:src="@drawable/ic_alert_pin_32dp"
app:layout_constraintBottom_toBottomOf="@+id/createTaskViewGuardianSettingsThirdPinIcon"
app:layout_constraintStart_toEndOf="@+id/createTaskViewGuardianSettingsThirdPinIcon"
app:layout_constraintTop_toTopOf="@+id/createTaskViewGuardianSettingsThirdPinIcon" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/createTaskViewStartButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="@drawable/button_blue_roundsquare"
android:elevation="2dp"
android:text="Start Task"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="26dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/createTaskViewFormContainer" />
<Button
android:id="@+id/createTaskViewPanicButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:background="@drawable/button_red_roundsquare_unfocused"
android:elevation="2dp"
android:text="Request Help"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="26dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<include
android:id="@+id/voiceRecordOverlayLayout"
layout="@layout/overlay_voice_record"
android:visibility="gone" />
<include
android:id="@+id/teamSettingsOverlayLayout"
layout="@layout/overlay_team_settings"
android:visibility="gone" />
<include
android:id="@+id/submitCreateTaskOverlayLayout"
layout="@layout/overlay_submit_create_task"
android:visibility="gone" />
<include
android:id="@+id/updatingTeamRulesOverlayLayout"
layout="@layout/overlay_updating_team_rules"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>
有人遇到过类似的问题吗?
我的布局有什么问题吗?
我对如何修理它没有主意。谢谢!
最佳答案
我用ConstraintLayout 1.0.2
重现了这种行为。但是,只需将gradle文件中的依赖项更改为最新版本(1.1.0-beta6
)
'com.android.support.constraint:constraint-layout:1.1.0-beta6'
自动解决了这个问题,而没有对xml做任何更改。不必要的空间消失了,而且视图的位置正确。