问题描述
我想在片段
容器加载 SupportMapFragment
。我没有错误,我的API密钥是罚款,谷歌Play服务库是进口的,所有的权限被调用。
我称之为 MapFragment
是这样的:
MapaFragment片段=新MapaFragment();
FragmentTransaction平方英尺= getFragmentManager()调用BeginTransaction()。
ft2.replace(android.R.id.tabcontent,片段)
。承诺();
的片段
如下:
公共类MapaFragment扩展SupportMapFragment {
私人视图V;@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
super.onCreateView(充气器,容器,savedInstanceState);
V = inflater.inflate(R.layout.mapa,NULL); 返回伏;
}
和对地图的布局很简单,只要这样的:
<?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /地图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>
您已经添加SupportMapFragment在XML布局文件,它没有必要在code重新添加或覆盖onCreateView方法,只需注释掉这些
MapaFragment片段=新MapaFragment();
FragmentTransaction平方英尺= getFragmentManager()调用BeginTransaction()。
ft2.replace(android.R.id.tabcontent,片段)
。承诺();
和这些
私人视图V;@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
super.onCreateView(充气器,容器,savedInstanceState);
V = inflater.inflate(R.layout.mapa,NULL); 返回伏;
}
code的
线并尝试运行应用程序
I want to load a SupportMapFragment
in a Fragment
container. I get no errors, my API Key is fine, Google Play Services Library is imported and all permissions are called.
I call the MapFragment
this way:
MapaFragment fragment = new MapaFragment();
FragmentTransaction ft2 = getFragmentManager().beginTransaction();
ft2.replace(android.R.id.tabcontent, fragment)
.commit();
The Fragment
is as follows:
public class MapaFragment extends SupportMapFragment {
private View v;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
v=inflater.inflate(R.layout.mapa, null);
return v;
}
And the layout for the map is as simple as this:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapa"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
You have already added SupportMapFragment in xml layout file, it's not necessary to add it again in code or override onCreateView method, just comment out these
MapaFragment fragment = new MapaFragment();
FragmentTransaction ft2 = getFragmentManager().beginTransaction();
ft2.replace(android.R.id.tabcontent, fragment)
.commit();
and these
private View v;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
v=inflater.inflate(R.layout.mapa, null);
return v;
}
lines of code and try to run the app
这篇关于SupportMapFragment出现空白(谷歌地图V2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!