在ConstraintLayout中向<include>添加约束

Nit*_*hin 6 android android-layout android-constraintlayout

请看看我的xml:

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize">

    <RelativeLayout
        android:id="@+id/layout_info"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <include
        layout="@layout/page"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我无法添加约束<include>.该app命名空间不起作用(它的工作原理为RelativeLayout)和自动填充不显示约束属性.我希望包含的布局高度是其余的空间ConstraintLayout,但是如何在没有约束的情况下做到这一点!请帮忙.

Nil*_*hod 9

试试这个

 <android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize">

    <RelativeLayout
        android:id="@+id/layout_info"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <include
         layout="@layout/page"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

  • 尺寸很重要.在'<include'之后的工作是宽度和高度. (5认同)

asw*_*ala 5

<include layout="@layout/layout_no_friends_avalable"
                 android:id="@+id/inc_no_friend"
                 android:layout_width="match_parent"
                 android:layout_height="0dp"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/toolbar_main"
        />
Run Code Online (Sandbox Code Playgroud)

<include>标签中添加约束时,我们必须使用android:layout_widthandroid:layout_height这两个属性。