Android 安卓谷歌地图可以';找不到
我有一个在应用程序上实际显示地图的布局Android 安卓谷歌地图可以';找不到,android,google-maps,Android,Google Maps,我有一个在应用程序上实际显示地图的布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/fragment_create_instant_album_create_button_text_view" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="@string/instant_album_info"
android:textColor="@color/pico_clay" />
<EditText
android:id="@+id/fragment_create_instant_album_album_name_text_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:background="@drawable/blue_border_edittext_unselected"
android:hint="@string/album_name"
android:paddingLeft="15dp"
android:textColor="@color/pico_dark_grey"
android:textColorHint="@color/pico_grey_blue"
android:textSize="@dimen/text_medium" />
<fragment
android:id="@+id/fragment_create_instant_album_map_fragment"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="15dp"
class="com.google.android.gms.maps.SupportMapFragment"
android:background="@drawable/blue_border_edittext_unselected"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:tag="map" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center_vertical"
android:paddingTop="8dp" >
<RadioGroup
android:id="@+id/fragment_create_instant_album_privacy_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</RadioGroup>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<com.coapps.pico.fonts.RobotoTextView
android:id="@+id/fragment_create_instant_album_create_button_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/pico_salmon"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="@string/create_instant_album"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@android:color/white" />
</RelativeLayout>
为什么??我做错了什么?试试这个来获取你的地图
GoogleMap mMap = ((SupportMapFragment) getActivity()
.getSupportFragmentManager().findFragmentById(R.id.fragment_create_instant_album_map_fragment))
.getMap();
如果仍然为空,请尝试此替代方法
<FrameLayout
android:id="@+id/fl_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
/>
在片段的onDetach()中,输入以下代码
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class
.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
您是否在清单文件和Internet权限中添加元数据
<uses-permission android:name="android.permission.INTERNET" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="******2wuOppWIMVpr8DF6u6ydKf********" />
您可以检查此链接请再次阅读问题“未显示相关映射”,该问题清楚地表明,在尝试使用findFragmentByTag()查找映射片段时获取null。检查:getActivity().getSupportFragmentManager().findFragmentById始终返回null,但它对我有效,您是否尝试过调试,但实际结果是空的,并且您在片段的onCreateView中进行调试?虽然它应该对您有效,但如果失败,我将为您提供另一个解决方案。但是,首先要确保通过调试您的代码并找出isokay的实际原因,这不起作用,然后等待,我将为您提供另一个解决方案,希望这能起作用
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class
.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
<uses-permission android:name="android.permission.INTERNET" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="******2wuOppWIMVpr8DF6u6ydKf********" />