【发布时间】:2017-12-27 11:48:21
【问题描述】:
基本上,我有一个 ConstraintLayout 作为根,然后有 2 个 ConstraintLayouts 作为子级,垂直对齐(以 wrap-content 作为其高度)和最后一个第三个,以填充所有剩余空间(0dp 高度,设置所有约束) .但是,这第三个 ConstraintLayout,首先将 wrap-content 作为其高度,当我将高度更改为 0dp 时,第三个布局中的所有视图看起来都没有高度(它们的高度为 wrap-content,这不是改变)。当我手动输入高度时,例如'30dp' 作为视图的高度,它可以工作,但视图高度的包装内容不起作用。此外,设置约束,即底部提升视图。有谁知道怎么回事?
This 是我得到的行为。
== 约束布局(根)
== ConstraintLayout(包装内容)
== ConstraintLayout(包装内容)
== ConstraintLayout(高宽0dp,所有约束集,填充剩余空间)
=== 视图(宽度为 0dp,高度为 wrap_content,但不显示高度(主要是 ImageView 和 EditTexts)。
看到这个image,红色区域是我遇到问题的 ConstraintLayout,并且布局中的 View 是黄色的。
这是我的整个布局文件:
<?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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" android:id="@+id/constraintLayout28" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_team" android:id="@+id/imageView17" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp" android:layout_marginStart="8dp" />
<AutoCompleteTextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
android:id="@+id/cL1" app:layout_constraintLeft_toRightOf="@+id/imageView17"
android:layout_marginLeft="8dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"
android:layout_marginStart="8dp" android:padding="4dp" android:background="@drawable/edittext"
android:layout_marginEnd="8dp" android:hint="Opdrachtgever*" />
<LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/cL1"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imageView17" android:layout_marginLeft="8dp"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp">
<AutoCompleteTextView android:layout_width="0dp" android:layout_height="wrap_content"
android:id="@+id/cL2" android:padding="4dp" android:background="@drawable/edittext"
android:layout_weight="1" android:layout_marginRight="4dp" android:hint="Voornaam" />
<AutoCompleteTextView android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/cL3"
android:padding="4dp" android:background="@drawable/edittext" android:layout_weight="1" android:layout_marginLeft="4dp"
android:hint="Achternaam" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="1px"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/constraintLayout28"
android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent" android:background="@color/dividerColor"
android:id="@+id/constraintLayout29" android:layout_marginStart="8dp" android:layout_marginEnd="8dp">
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/constraintLayout29"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" android:id="@+id/constraintLayout30"
android:layout_marginStart="8dp" android:layout_marginEnd="8dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_location" android:id="@+id/imageView19" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
android:layout_marginStart="8dp" />
<LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/imageView19" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp" android:weightSum="1"
app:layout_constraintHorizontal_bias="0.0" android:id="@+id/linearLayout2" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<AutoCompleteTextView android:layout_width="0dp" android:hint="Straat" android:id="@+id/cL4"
android:layout_height="wrap_content" android:padding="4dp" android:background="@drawable/edittext"
android:layout_weight="0.8" android:layout_marginRight="4dp" />
<EditText android:layout_width="0dp" android:hint="#" android:id="@+id/cL4Number"
android:layout_height="wrap_content" android:padding="4dp" android:background="@drawable/edittext"
android:layout_weight="0.2" android:layout_marginLeft="4dp" />
</LinearLayout>
<EditText android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/cL5"
android:hint="Stad" android:padding="4dp" android:background="@drawable/edittext" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/linearLayout2"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imageView19" android:layout_marginLeft="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
android:layout_marginStart="8dp" android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="1px"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/constraintLayout30"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" android:background="@color/dividerColor"
android:id="@+id/constraintLayout31" android:layout_marginStart="8dp" android:layout_marginEnd="8dp">
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout31" android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" app:layout_constraintBottom_toTopOf="@+id/cL6"
android:layout_width="0dp" android:layout_height="0dp">
<ImageView android:layout_width="0dp" android:layout_height="0dp" app:srcCompat="@drawable/ic_description"
android:id="@+id/imageView20" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="1.0" />
<EditText android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/cL7"
android:hint="Referentie nummer" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp" android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imageView20" android:layout_marginLeft="8dp" android:padding="4dp"
android:background="@drawable/edittext" />
<AutoCompleteTextView android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/cL8"
android:hint="Project" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/cL7"
app:layout_constraintLeft_toRightOf="@+id/imageView20" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" android:padding="4dp" android:background="@drawable/edittext" />
<EditText android:layout_width="0dp" android:layout_height="0dp" android:id="@+id/cL9"
android:hint="Omschrijving" android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imageView20" android:layout_marginLeft="8dp" android:padding="4dp"
android:background="@drawable/edittext" app:layout_constraintHorizontal_bias="0.0" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/cL8"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp" />
</android.support.constraint.ConstraintLayout>
<ImageView android:layout_width="0dp" android:layout_height="wrap_content"
app:srcCompat="@drawable/bt_cL6" android:id="@+id/cL6"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" android:adjustViewBounds="true" android:scaleType="fitXY" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
你能发布完整的布局吗?
-
@AskQ 我更新了帖子。
-
您在 CL 以下的 CL 有问题,ID 为 constraintLayout31。它的高度是问题吧?
-
@AskQ 我的布局及其内容有问题。 CL 本身的尺寸很好,所有字段都正确并且应用正确,但是,它的所有子视图都不显示任何形式的高度(如我原始帖子中的图像所示),即使它们具有 wrap-content 为他们的身高。
-
是的,因为它的 0dp。检查我发布的xml!
标签: java android android-constraintlayout