【发布时间】:2019-05-05 21:39:28
【问题描述】:
我想在FrameLayout 中显示我的片段的预览。
实际上我只想在android studio中显示它,我不想渲染它。
我的解决方案:
在 Xml 中,我使用 include 标签加载 home_fragment 预览:
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/nav_view"
android:layout_below="@id/my_toolbar">
<include layout="@layout/home_fragment" />
</FrameLayout>
在 onCreate 方法中,我删除了 FrameLayout 的所有子视图:
FrameLayout frameLayout = findViewById(R.id.main_frame);
frameLayout.removeAllViews(); // remove static preview in activity_main.xml
现在一切正常。 但我认为有更好的方法。
【问题讨论】:
标签: android