2017-09-14 98 views
2

请看看我的xml:约束<include>里面添加ConstraintLayout

<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> 

我无法约束添加到<include>app名称空间不起作用(它适用于RelativeLayout)并且自动填充不显示约束属性。我希望包含的布局的高度为ConstraintLayout中的剩余空间,但我该如何做到这一点没有限制!请帮忙。

回答

2

的Android Studio不会在包括标签自动完成constraintLayout参数,但他们确实有它的影响,只要你给包括大小。

试试这个

<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> 
0

试试这个:

<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>