【发布时间】:2015-03-12 09:50:20
【问题描述】:
我知道这个问题已经被问过几次了,但我无法通过查看它们来解决我的问题。我创建了一个导航抽屉。导航抽屉自然有助于切换片段。在这样一个片段中,我想显示一张谷歌地图。
map_fragment.xml:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
MapFragment:
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MapFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.map_fragment, container, false);
GoogleMap map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
return view;
}
}
行:
GoogleMap map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
总是显示:
无法从 Fragment 投射到 SupportMapFragment
我不确定为什么会出现这种情况?我哪里错了?我已经在清单中提供了所有必需的权限,因为我可以在其他活动中查看谷歌地图。
【问题讨论】:
-
问了很多次......你应该决定“支持”或“正常”......不要同时使用两者......
-
@Selvin 这两种组合在我的情况下都不起作用
-
天哪,不工作?这是什么意思?程序员字典中没有这样的词....无论如何检查导入...了解什么是类层次结构...我很确定 SupportMapFragment 不是从 android.app.Fragment 派生的...但 MapFragment 是。 ..
标签: java android google-maps android-fragments