Android. Как зависит от идентификаторов включенного макета - PullRequest
0 голосов
/ 25 марта 2020

У меня есть первый макет, который я хочу включить

// first_layout.xml
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tvFirstLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First layout text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

И у меня есть второй макет, где будет включен первый макет

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <include layout="@layout/first_layout"/>

    <TextView
        android:id="@+id/tvSecondLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text of second layout"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tvFirstLayout"/> // THIS IS THE QUESTION

</androidx.constraintlayout.widget.ConstraintLayout>

Теперь проблема заключается в использовании первого textView в качестве ограничения для второй textView. Любые решает это?

Ответы [ 3 ]

0 голосов
/ 25 марта 2020

Вы можете установить идентификатор для тега включения

<include android:id="@+id/include" 
         layout="@layout/first_layout"/>

<TextView
    android:id="@+id/tvSecondLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text of second layout"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/include"/> // Note you can reference include tag with id

и затем ссылаться на тег включения с его идентификатором.

0 голосов
/ 25 марта 2020
<include layout="@layout/first_layout"
        android:id="@+id/include"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Теперь вы можете установить ограничения.

0 голосов
/ 25 марта 2020

Дайте height, width и id тегу <include>, а затем вы можете установить ограничения.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...