有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将全屏片段替换为另一个片段

我有一个片段(fragment_1),它在主活动开始时显示,并显示全屏布局(layout_1)。现在我添加了一个按钮,点击它将开始一个新的片段(片段_2),并用我的新布局(布局_2)替换整个布局(布局_1)

我的第一个片段(fragment_1)有一个滚动视图作为我的根视图

<ScrollView
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:fitsSystemWindows="true"
安卓:background="#fff"
安卓:scrollbarSize="0dp"
安卓:id="@+id/scroll_main"
tools:context=".MainActivity">

<RelativeLayout
    安卓:layout_width="match_parent"
    安卓:layout_height="wrap_content"
    安卓:fitsSystemWindows="true">
....

</RelativeLayout>

</ScrollView>

现在我想点击一个按钮开始一个新的片段(fragment_2),然后显示另一个布局(layout_2),但我不知道怎么做。 我的主要活动有这样一个框架布局

<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:id="@+id/root_container">

我曾经用

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

在此之后,我开始我的第一个片段,并显示布局_1

现在从片段1开始,我想开始片段2并显示布局。我在网上读过一些文章和文档,但找不到关于这个问题的解决方案。请注意:“我不想简单地替换我的布局_1的一部分,并用我的布局_2替换它,而是希望我的布局_1在点击按钮时完全被布局_2替换。”


共 (0) 个答案