gpt4 book ai didi

android - 替换包含布局

转载 作者:搜寻专家 更新时间:2023-11-01 08:40:26 25 4
gpt4 key购买 nike

我在 Android Studio 中生成了新的 Android 项目,我在其中为带有 Fragment 的空白 Activity 选择了新模板,我发现它的结构与旧的有点不同。它使用标签和 CoordinatorLayout。那么我应该如何在此 include 标签内切换布局?

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

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

<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

最佳答案

include 替换为容器,例如框架布局。在运行时膨胀您要添加的布局,并在容器上调用 addView。要替换您已有的内容,您可以调用 removeView,然后使用新内容调用 addView

关于android - 替换包含布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33147403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com