Android 无法用另一个片段替换选项卡内的片段
我正在开发Android应用程序,它在操作栏中有4个标签(main_activity.xml) 在一个选项卡中,我将其称为MapListFragment(map_list_fragment.xml),我必须显示两个不同的片段(一些数据的列表和地图视图表示)。所有其他选项卡都是片段,与MapListFragment(id/main\u fragments\u容器)放在同一个容器中 所以,首先显示map Fragment,底部显示map和list按钮。此时只显示一个片段(映射或列表),单击按钮(映射或列表)可以显示其他片段,然后再次单击按钮返回到第一个片段。这些映射和列表片段的容器是(id/fragments\u Container)。我通过对FragmentTransaction调用replace()方法来更改此片段,并转发ActionBar TabListener用于更改选项卡的相同容器(id/main\u fragments\u container)。我还尝试为这个选项卡创建新的容器,并将其用于该选项卡内的所有操作,但我遇到了同样的问题。更改此片段效果很好,但是 然后,我在ActionBar上添加了一个按钮,它调用了新的片段,该片段应该表示添加一些数据的视图。这个片段的容器是(id/main\u fragments\u Container),问题是,当我返回到MapListFragment时,我不能得到和initial相同的行为。第一个问题是,这是最佳工作实践还是我应该称之为“活动”而不是“片段” 当我从ActionBar按钮调用new Fragment时,我总是删除map Fragment(我得到了相同的结果,当我不删除时),当我返回MainFragment时,会显示空白视图,尽管我调用addToBackStack()方法 所以我这里有很多问题,我希望我能解释其中的一些问题,有人知道我能做些什么吗 包含4个选项卡的MainActivity的XML布局 main_activity.xmlAndroid 无法用另一个片段替换选项卡内的片段,android,android-layout,android-fragments,google-maps-android-api-2,mapfragment,Android,Android Layout,Android Fragments,Google Maps Android Api 2,Mapfragment,我正在开发Android应用程序,它在操作栏中有4个标签(main_activity.xml) 在一个选项卡中,我将其称为MapListFragment(map_list_fragment.xml),我必须显示两个不同的片段(一些数据的列表和地图视图表示)。所有其他选项卡都是片段,与MapListFragment(id/main\u fragments\u容器)放在同一个容器中 所以,首先显示map Fragment,底部显示map和list按钮。此时只显示一个片段(映射或列表),单击按钮(映射
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@android:color/white">
<LinearLayout
android:id="@+id/main_fragments_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
MapListFragment布局,包含片段和两个按钮,动态添加片段
map\u list\u fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/events_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white" >
<LinearLayout
android:id="@+id/fragments_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white"
style="?android:attr/buttonBarButtonStyle"/>
<Button
android:id="@+id/button_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
我也有同样的问题。