ConstraintLayout显示高度,但实际上是0

时间:2018-02-08 17:09:37

标签: android android-layout android-xml android-constraintlayout

我在布局文件中有ConstraintLayout,当我将height的{​​{1}}设置为 0dp 并设置其他约束时,我可以看到布局大小与我想要的大小相同(here),但是,当我在布局中放置另一个ConstraintLayout时(在本例中为View),它不会调整大小它的MapView 高度here)!这是我的整个XML文件:

parent

任何人都可以向我解释这种行为并帮助我获得<?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:mapbox="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/dialogContainer" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageButton android:id="@+id/closeDialogButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="16dp" android:layout_marginTop="8dp" android:background="@drawable/ic_close_workorder" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/dialogInfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="24dp" android:layout_marginStart="24dp" android:layout_marginTop="8dp" android:fontFamily="@font/open_sans_semibold" android:text="TextView" android:textColor="@color/textTint" android:textSize="15sp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/dialogTitle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:layout_marginStart="24dp" android:layout_marginTop="8dp" android:fontFamily="@font/gotham_medium" android:text="TextView" android:textColor="@color/primaryDark" android:textSize="20sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/dialogInfo" /> <android.support.constraint.ConstraintLayout android:id="@+id/constraintLayout6" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/dialogTitle"> <ImageView android:id="@+id/imageView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:layout_marginTop="24dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_description" /> <TextView android:id="@+id/descriptionText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:layout_marginTop="8dp" android:fontFamily="@font/open_sans_light" android:text="TextView" android:textColor="@color/primaryDark" android:textSize="14dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toRightOf="@+id/imageView6" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> <android.support.constraint.ConstraintLayout android:id="@+id/divider1" android:layout_width="0dp" android:layout_height="1dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="4dp" android:background="@color/dividerColor" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout6"> </android.support.constraint.ConstraintLayout> <android.support.constraint.ConstraintLayout android:id="@+id/constraintLayout7" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="4dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/divider1"> <ImageView android:id="@+id/imageView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:layout_marginTop="24dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_materials" /> <TextView android:id="@+id/materialsText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:layout_marginTop="8dp" android:fontFamily="@font/open_sans_light" android:text="TextView" android:textColor="@color/primaryDark" android:textSize="14dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toRightOf="@+id/imageView7" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> <android.support.constraint.ConstraintLayout android:id="@+id/divider2" android:layout_width="0dp" android:layout_height="1dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="4dp" android:background="@color/dividerColor" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout7"> </android.support.constraint.ConstraintLayout> <android.support.constraint.ConstraintLayout android:id="@+id/constraintLayout9" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="4dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/divider2"> <ImageView android:id="@+id/imageView8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:layout_marginTop="24dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_contact" /> <TextView android:id="@+id/contactText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:layout_marginTop="8dp" android:fontFamily="@font/open_sans_light" android:text="TextView" android:textColor="@color/primaryDark" android:textSize="14dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toRightOf="@+id/imageView8" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> <TextView android:id="@+id/noMapInstruction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Geen kaart beschikbaar" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout9" /> <android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout9"> <com.mapbox.mapboxsdk.maps.MapView android:id="@+id/locationMap" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" mapbox:mapbox_cameraZoom="11" mapbox:mapbox_renderTextureMode="true" mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" /> </android.support.constraint.ConstraintLayout> <android.support.constraint.ConstraintLayout android:id="@+id/constraintLayout10" android:layout_width="0dp" android:layout_height="wrap_content" android:background="@color/fadedWhite" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout9"> <TextView android:id="@+id/locationText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:layout_marginTop="24dp" android:fontFamily="@font/open_sans_light" android:text="TextView" android:textColor="@color/primaryDark" android:textSize="14dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toRightOf="@+id/imageView10" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/imageView10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:layout_marginLeft="16dp" android:layout_marginTop="24dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_location" /> </android.support.constraint.ConstraintLayout> <ImageView android:id="@+id/openWorkOrder" android:layout_width="0dp" android:layout_height="wrap_content" android:adjustViewBounds="true" android:cropToPadding="false" android:src="@drawable/button_open_workorder" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" /> </android.support.constraint.ConstraintLayout> 的全高吗? This是我尝试实现的目标,但没有中间视图(联系人图标)的信息。基本上,ConstraintLayout应在后面显示位置文字。

2 个答案:

答案 0 :(得分:0)

0dp及其容器更改wrap_content MapView。也可能用于其他布局。

另外,我发现你使用了很多ConstraintLayout s。例如,分隔符(divider1divider2)是ConstraintLayout,但可能只是View s,这会提高性能。

答案 1 :(得分:0)

这些限制:

    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"

忽略layout_width中设置的宽度,并将此视图的左侧连接到父级的左侧,右侧的右侧,结果将是match_parent的宽度。

类似地,你可以做Top_topTopOf =“parent”和Bottom_toBottomOf =“parent”但是因为如果你想要线性放置你在屏幕上有更多的视图你可以使用Top_toBottomOf =“@ id / other”