Android 如何强制空ConstraintLayout填充其父容器?

Android 如何强制空ConstraintLayout填充其父容器?,android,android-constraintlayout,Android,Android Constraintlayout,我使用了一个ConstraintLayout作为覆盖。它应该和它的父容器一样宽和一样高。然而,出于某种奇怪的原因,它并没有垂直填充其父对象(而是水平填充)。以下是相关的XML: <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.and

我使用了一个
ConstraintLayout
作为覆盖。它应该和它的父容器一样宽和一样高。然而,出于某种奇怪的原因,它并没有垂直填充其父对象(而是水平填充)。以下是相关的XML:

<androidx.constraintlayout.widget.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"
    tools:context=".ui.home.HomeFragment">

    <androidx.constraintlayout.widget.ConstraintLayout  <-- This is the overlay
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80000000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>


问题很可能是您的尺码规格。从:

重要提示:对于ConstraintLayout中包含的小部件,不建议使用MATCH_父项。类似的行为可以通过使用MATCH_约束来定义,并将相应的左/右或上/下约束设置为“parent”


此或约束确实应该有lint规则。您应该拒绝
match\u parent

而不是“match\u parent”使用“0dp”匹配约束它应该用match parent或0dp填充屏幕。但问题是颜色——8000000是透明代码。我想这就是为什么它看起来像是扩展到父视图。@Pawel两者都不起作用。@BerkayKireçci颜色不重要。奇怪的是,它在Android Studio预览中占据了屏幕,但在设备上却没有。