2

I have added a map fragment in xml with some additional views in LinearLayout underneath it

  <fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="4"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"

    />

This how my activity looks like: https://i.stack.imgur.com/2sc8b.jpg (Can't post images yet)

When I click "My Trails", new fragment should be created

    MyTrailsFragment myTrailsFragment = new MyTrailsFragment();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.add(R.id.map_activity_layout , myTrailsFragment, "mytrailsfragment").addToBackStack("").commit();

Now I don't understand why instead of covering full screen, new fragment just takes 80% of it with map fragment being compressed at the top.

https://i.stack.imgur.com/EI5vR.jpg

I suspect that map fragment is somehow hardcoded in activity layout and without being able to make transaction with it I won't be able to hide it. I tried to add map fragment in framelayout but I'm stuck with nullpointerexception at

    MapFragment mapFragment = new MapFragment();
    FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.mapframelayout, mapFragment, "mapfragment").commit();

    MapFragment mf = (MapFragment) getFragmentManager().findFragmentByTag("mapfragment");

    map = mf.getMap();                   <<<<<<< HERE - NullPointerException

    map.getUiSettings().setZoomControlsEnabled(true);
    map.getUiSettings().setMyLocationButtonEnabled(true);
    map.setMyLocationEnabled(true);

So my questions are:

  1. Why is map fragment showing on the top of the screen and how to workaround this problem
  2. Where I fail to properly add map fragment in java.
pazera
  • 21
  • 1
  • Now I think that I could use this map fragment being at the top of the screen but how should I add "My Trails" fragment so that all of it would be visible. Now it is cut off at the bottom. – pazera Aug 27 '15 at 23:22

0 Answers0