Comment inclure la contrainte de mise en page à une autre contrainte de mise en page et de définir des contraintes entre chaque

Je suis en utilisant constraintLyout v 1.0.1.

Je voudrais inclure dans mon xml un sous ConstraintLayout correspondant à une partie de ma mise en page globale (qui lui-même est un ConstraintLayout). J'ai divisé la mise en page en deux xmls afin d'utiliser cette sous partie ailleurs

J'ai essayé ceci mais je n'ai pas de contrôle sur l'endroit où placer mes sous contrainte de mise en page dans le parent. Je me demande si je dois tout mettre dans le même fichier xml ou si leur est une solution pour utiliser des fichiers séparés.

tmp_1.xml

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LABEL1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="16dp"
        />
    <TextView
        android:id="@+id/label_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LABEL2"
        app:layout_constraintStart_toStartOf="@id/label"
        app:layout_constraintEnd_toEndOf="@id/label"
        app:layout_constraintTop_toBottomOf="@id/label"
        android:layout_marginTop="16dp"
        />

    <include layout="@layout/tmp_2" />
</android.support.constraint.ConstraintLayout>

tmp_2.xml

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:id="@+id/view_80"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="80th element"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="10dp"
        android:layout_marginStart="12dp"
        />
</android.support.constraint.ConstraintLayout>

Le résultat est cette Résultat réel

Mais je le veux ce Résultat attendu

J'ai essayé ceci mais ça ne fonctionne pas

<include 
    app:layout_constraintTop_toBottomOf="@id/label_2"
    layout="@layout/tmp_2" />

Je serais heureux d'avoir vos solutions,

Merci

InformationsquelleAutor Kélian | 2017-04-28