当我在运行时用SupportMapFragment替换容器时,它不会填充Parent。它仅部分占用屏幕。
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>
答案 0 :(得分:5)
看起来你已经设置了填充。删除你的填充,再次构建你的应用程序,并检查它是否有效。