2017-09-14 138 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>