Хорошо, это может быть немного сложно, но мне интересно, возможно ли это.
Скажем, у меня есть основной макет активности - который содержит include
, который включает в себя один конкретный фрагмент -с именем activity_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- some other things... -->
<include
android:id="@+id/mainContent"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/itemBelow"
app:layout_constraintTop_toBottomOf="@+id/itemAbove">
<!-- load fragments here -->
</include>
<!-- some other things... -->
</android.support.constraint.ConstraintLayout>
и у меня есть макет фрагмента, например: fragment_1.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- something... -->
</android.support.constraint.ConstraintLayout>
Я знаю в activity_main.xml
, я могу просмотреть fragment_1.xml
с помощьюдобавив tools:layout="@layout/fragment_1"
в include
;
и в fragment_1.xml
, я могу просмотреть activity_main.xml
, добавив tools:showIn="@layout/activity_main"
в базу ConstraintLayout
.
Но вот идетвопрос: для многократного использования макета, может быть другой фрагмент, который показан в include
, и если я последую методу выше - скажем, в fragment_2.xml
я напишу:
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/activity_main">
<!-- something... -->
</android.support.constraint.ConstraintLayout>
Я бы просто увидел fragment_1.xml
внутри activity_main.xml
в предварительном просмотре.
Есть ли какой-либо способ, который показывает fragment_2.xml
внутри activity_main.xml
- при предварительном просмотре fragment_2.xml
в AndroidStudio?
Более того: если внутри activity_main.xml
будет больше include
s, будет ли метод все еще работать?