0
我有在抽屉布局的第二个菜单中使用地图的应用程序。当我试图用地图膨胀片段时,应用程序崩溃。Android:在抽屉布局中使用地图扩展片段时出错
以下是代码:
if (rootView != null) {
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null) {
parent.removeView(rootView);
}
}
try {
rootView = inflater.inflate(R.layout.fragment_map, container, false);
} catch (Exception e) {
e.printStackTrace();
}
以下是生成的异常:
android.view.InflateException:二进制XML文件行#23:错误充气类片段
我已经尝试了很多堆栈和其他平台上的解决方案,但徒劳无功。
这是怎么了我在我的XML使用父母的RelativeLayout内地图片段:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
我也试过在其onDestroyView
methos取出地图片段:
@Override
public void onDestroyView() {
super.onDestroyView();
SupportMapFragment fragment = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map));
try{
if (fragment != null)
getChildFragmentManager().beginTransaction().remove(fragment).commit();
}catch(Exception e){
}
}
以下是清单文件数据:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.app.myapp.SplashActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.app.myapp.LoginActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
>
</activity>
<activity
android:name="com.app.myapp.MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
按我的方式,你应该从'片段Transaction'删除'地图Fragment'当你去到另一个'片段'或屏幕。 –
是的,我已经在OnDestroyView方法中完成了它,但它没有解决我的问题。问题是带有地图的片段在首次启动时崩溃。 –
如何?发布你的代码...也发布你的清单 –