0

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?

Eduardo Naveda
  • 1,880
  • 3
  • 15
  • 30

1 Answers1

1

After hours of fiddling and trying to find a workaround I found out that there's a updated MapView on Google Maps Android API v2, so for those having the same issue where you need to nest within a ViewPager page fragment a MapFragment just use the MapView.

I found about MapView in the following SO question: Should I use MapView or MapFragment

Community
  • 1
  • 1
Eduardo Naveda
  • 1,880
  • 3
  • 15
  • 30