【发布时间】:2015-07-01 13:24:06
【问题描述】:
我有这个 xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#f00"
android:gravity="center">
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map" />
</LinearLayout>
这是我在 Fragment 的 onCreateView 方法中的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.map_activity, container, false);
mapView = (MapView) view.findViewById(R.id.map);
mMap = mapView.getMap();
if (mMap== null)
{
Toast.makeText(getActivity().getBaseContext(),"Google Maps not Available",
Toast.LENGTH_LONG).show();
}
locReader = (LocationReader) new LocationReader(getActivity().getBaseContext(), true);
this.loc = locReader.getLastKnownLocation();
moveCamMyPosition(loc);
return view;
}
片段加载正常,但 nMap 为空。 Toast 显示“Google 地图不可用”。
我找不到错误。
【问题讨论】:
-
你有没有在menifest中创建和定义密钥
-
您在哪个设备上运行此代码?好像你在使用模拟器。
-
@aldakur 错误的布局夸大了
map_activity。片段的布局是否相同?? -
是的。这个名字不合适。在 Activity 的最后 y 启动地图中,但现在我想要在 Fragment 中进行布局
标签: android dictionary fragment