【发布时间】:2017-11-18 08:53:11
【问题描述】:
我在片段的主要活动中有这段代码。
<LinearLayout 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:id="@+id/mainView"
android:orientation="vertical"
android:layout_marginBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/mainView2"/>
</LinearLayout>
我在我的主要活动中使用此代码来膨胀片段
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().add(R.id.mainView,new MainViewFragment())
.add(R.id.mainView2,new SecondProductLayout())
.commit();
但我仍然得到第一个片段视图,我做错了什么,我该如何解决这个问题?
【问题讨论】:
-
为什么mainView2在mainView里面? mainView2 不应该低于 mainView 吗?
-
@ChinLoong 理论上应该,但它会抱怨多个根标签。
标签: android android-fragments android-activity