所以我目前正在制作基于GoogleMaps的游戏。因为我想制作相机,我需要像素中整个谷歌地图的大小。
这就是我的意思:
我已经尝试过:
// pre generated by android studios
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
int width = mapFragment.getView().getMeasuredWidth();
int height = mapFragment.getView().getMeasuredHeight();
String widthAndHeight = width+" "+height;
但它只返回null。这个片段有什么问题?还有其他方法来计算谷歌地图的完整尺寸吗?或者这只是返回当前显示的地图部分的大小?
答案 0 :(得分:3)
基于If I call getMeasuredWidth() or getWidth() for layout in onResume they return 0,你可以这样工作:
mapView = mapFragment.getView();
mapView.post(new Runnable() {
@Override
public void run() {
int width = mapView.getMeasuredWidth();
int height = mapView.getMeasuredHeight();
String widthAndHeight = width + " " + height;
}
});