Android ViewBinding-如何动态切换/选择布局(<;include>;)?

Android ViewBinding-如何动态切换/选择布局(<;include>;)?,android,android-viewbinding,Android,Android Viewbinding,我计划为概要文件片段提供两个布局版本,一个用于新用户,另一个用于登录用户 如何在片段的onCreateView()方法中动态切换/选择必要的布局 想到的最直接的想法是使用两个布局,并根据变量将其中一个隐藏在onCreateView()中。但我想知道是否有更聪明的方法 当前布局xml: 主要内容在第二个FrameLayout中,我想有两个版本可供选择 <?xml version="1.0" encoding="utf-8"?> <Fram

我计划为概要文件片段提供两个布局版本,一个用于新用户,另一个用于登录用户

如何在片段的
onCreateView()
方法中动态切换/选择必要的布局

想到的最直接的想法是使用两个
布局,并根据变量将其中一个隐藏在
onCreateView()
中。但我想知道是否有更聪明的方法


当前布局xml:
主要内容在第二个
FrameLayout
中,我想有两个版本可供选择

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:context=".ui.MainActivity">

    <ImageView
        android:id="@+id/profile_monk_head_imageview"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:contentDescription="@string/profile_monk_image_content_desc"
        android:src="@drawable/monk_head" />

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- This is what I want to switch out -->
        <FrameLayout ... >

    </androidx.core.widget.NestedScrollView>

</FrameLayout>

如果
layoutId
事先未知(也称为动态绑定),则使用
DataBindingUtil
版本。否则,请使用生成的绑定的充气方法来确保类型安全充气


这是为了创建片段的主布局,对吗?但是,我如何使用生成的绑定对象在布局A和B之间交换内容呢?哦,你的意思是我可以有两个完全独立的布局,然后决定要放大哪一个。但这似乎有点浪费,因为顶部的容器是相同的,所以我会有多余的代码。是否有一种方法可以只动态更改布局的一部分,如使用switchig