У меня есть макет в отдельном файле xml, который включается в другие файлы. Я хочу сослаться на включенный файл, поэтому я установил идентификатор. Но с идентификатором макет становится совершенно неструктурированным. Мини пример:
Родительский макет:
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<include layout = "@layout/test_include" />
</android.support.constraint.ConstraintLayout>
Включенный макет:
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:id = "@+id/constraint_parent"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<TextView
android:id = "@+id/t1"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "1"
app:layout_constraintEnd_toStartOf = "@id/t2"
app:layout_constraintStart_toStartOf = "@id/constraint_parent" />
<TextView
android:id = "@+id/t2"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "2"
app:layout_constraintEnd_toStartOf = "@id/t3"
app:layout_constraintStart_toEndOf = "@id/t1" />
<TextView
android:id = "@+id/t3"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "3"
app:layout_constraintStart_toEndOf = "@id/t2"
app:layout_constraintEnd_toEndOf = "@id/constraint_parent"/>
В результате получается следующий макет:

Но если я изменю тег include на следующий:
<include
android:id = "@+id/test"
layout = "@layout/test_include" />
Таким образом, схема полностью теряется. Нельзя ли добавить идентификатор в тег включения? Я хочу добавить тег включения два раза, поэтому я хочу добавить два разных идентификатора к двум включениям вместо прямой ссылки на родительский макет включенного макета.
Это действительно странно. Попробуйте добавить layout_width и layout_height в тег включения, это может исправить это странное поведение.
проблема во включенном макете, используйте вместо него этот xml
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:id = "@+id/constraint_parent"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<TextView
android:id = "@+id/t1"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "1"
app:layout_constraintTop_toTopOf = "parent"
app:layout_constraintEnd_toStartOf = "@id/t2"
app:layout_constraintStart_toStartOf = "parent" />
<TextView
android:id = "@+id/t2"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "2"
app:layout_constraintTop_toTopOf = "parent"
app:layout_constraintEnd_toStartOf = "@id/t3"
app:layout_constraintStart_toEndOf = "@id/t1" />
<TextView
android:id = "@+id/t3"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:text = "3"
app:layout_constraintTop_toTopOf = "parent"
app:layout_constraintStart_toEndOf = "@id/t2"
app:layout_constraintEnd_toEndOf = "parent"/>
</android.support.constraint.ConstraintLayout>
Спасибо. Замена @id/constraint_parent на parent в ограничениях исправляет это.