【发布时间】:2018-07-10 21:09:08
【问题描述】:
我有一个活动,上面已经有一堆元素,我想在活动上打开一个片段。
我想使用片段而不是活动,这样我就可以传递一些无法序列化或解析的对象。
到目前为止,我通过执行以下操作来做到这一点:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<RelativeLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
在我的活动中,我只是将我的fragment_container 更改为可见,然后我执行片段事务以将片段添加到那里,同时还将具有我活动的所有视图的main_container 设置为 GONE。
我知道这不是一个很好的解决方案,我一直在考虑将我的 main_container 中的所有视图移动到一个新片段,以便我可以将容器替换为一个或另一个。
在活动之上打开片段的最佳做法是什么?
【问题讨论】:
标签: java android performance android-layout