Question

When I replace the container with SupportMapFragment in runtime, it doesn't fill Parent. It occupies screen only partially.

HomeActivity2.java

package com.example.mapdemo;

import com.meteraid.android.services.LocationService;

import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;


public class HomeActivity2 extends BaseActivity2  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_activity2);

        LocationService locationService=LocationService.getInstance(this);
        Location location=locationService.getCurrentLocation();

        GoogleMapFragment mapFragment=new GoogleMapFragment();  


        mapFragment.setCurrentLocation(location);  



        android.support.v4.app.FragmentTransaction fragmentTransaction=getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container,mapFragment);     
        fragmentTransaction.commit();     


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home_activity2, menu);
        return true;
    }

}

GoogleMapFragment

package com.example.mapdemo;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;

import android.location.Location;

public class GoogleMapFragment extends SupportMapFragment {

    private static View view;
    private Location location;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        view = super.onCreateView(inflater, container, savedInstanceState); 


        Toast.makeText(getActivity(), "kkd",Toast.LENGTH_LONG).show();
        initMap(location);
        return view;

    }

    public void setCurrentLocation(Location location) {
        this.location = location;
    }

    public void initMap(Location location) {

        GoogleMap map = getMap();

        Log.e("Locationnnnnnnnnn", location+"");
        CameraPosition currentLocation = new CameraPosition.Builder()
                .target(new LatLng(location.getLatitude(), location
                        .getLongitude())).zoom(4f).bearing(0).tilt(0).build();

        map.moveCamera(CameraUpdateFactory.newCameraPosition(currentLocation));

        //map.setMyLocationEnabled(true);
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    }

}

activity_home_activity2.xml

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:id="@+id/fragment_container"  
            android:background="#cccccc"    
            tools:context=".HomeActivity2">           
 </FrameLayout>

enter image description here

Was it helpful?

Solution

It looks like you have set paddings. Remove your paddings, build your app again and check if that works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top