I have the following parent layout for an activity:
<?xml version="1.0" encoding="utf-8"?> <ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I also have the following layout for a Fragment
that goes into that ViewPager
:
<?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:orientation="vertical">
<FrameLayout
android:id="@+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
At runtime the FrameLayout
gets populated on the onCreateView()
method of the Fragment like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ViewGroup MapView = (ViewGroup) inflater.inflate(R.layout.frament_mood_map, container, false);
if(savedInstanceState == null) {
Fragment mapFragment = new SupportMapFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
//Adding map fragment to the FrameLayout.
transaction.add(R.id.mapLayout, mapFragment, "map").commit();
}
//Adding the mood panel.
ViewGroup mapLayout = (ViewGroup) MapView.findViewById(R.id.mapLayout);
mapLayout.addView(inflater.inflate(R.layout.mood_panel_layout, null));
...
return MapView;
}
The expected behavior is that since the container that gets populated by the Fragment
and the View
is a FrameLayout
, the former gets added first to the container, and then the later would be on top of the map, I want to show a map with a little panel on top which has buttons, I cannot define the Fragment
inside the XML because (citing the docs, and yes I've tried to do it):
Note: You cannot inflate a layout into a fragment when that layout includes a . Nested fragments are only supported when added to a fragment dynamically
What am I doing wrong? how can I workaround this?