11

Please take a look at my 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>

I'm not able to add constraint to the <include>. The app namespace doesn't work (it works for the RelativeLayout) and auto fill doesn't show the constraint attributes. I want the included layout's height to be the remaining space in the ConstraintLayout, but how do I do it without constraints! Please help.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Nithin
  • 221
  • 3
  • 14
  • What does "The app namespace doesn't work" mean? Do you mean it doesn't compile? Then what error message is given? Do you mean you get the wrong result? What result do you get? – LarsH Aug 23 '19 at 17:55

3 Answers3

14

Try this

 <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>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
8
<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"
        />

When adding constraints in <include> tag we must use android:layout_width and android:layout_height both attributes.

  • 1
    For the people that have styles defining margins and paddings inside their included xml, because the tag is overriding everything by defining height and width, the parameters also need to be brought to the front. (At least this is what happened to my divider) – Delark Sep 27 '20 at 03:44
0

try this:

<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: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"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57