我在我的主要活动中有这些片段的代码。
<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();但是我仍然得到了第一个片段视图,我做错了什么,我如何解决这个问题?
发布于 2017-11-18 09:00:53
将活动屏幕分成两部分,使活动中的片段膨胀。
发布于 2017-11-18 09:19:28
可以在xml中添加静态片段。请参阅这些链接:
发布于 2017-11-18 09:25:50
你必须用重量把你的布局分成两部分,然后像我们通常做的那样膨胀两个碎片。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.buffer.exampleapplication.MainActivity">
<FrameLayout
android:id="@+id/flFragment1"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/flFragment2"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>java代码来膨胀片段。
getFragmentManager().beginTransaction().replace(R.id.flFragment1, FragmentA.getInstance(msg)).commit();
getFragmentManager().beginTransaction().replace(R.id.flFragment2, FragmentA.getInstance(msg)).commit();https://stackoverflow.com/questions/47364226
复制相似问题