本文介绍了将Google地图渲染为片段时的黑色视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在渲染地图上滑动时,我在Android中使用的滑动菜单是
这是我的地图片段代码。
public class BasicMapActivity extends SherlockFragment {
private MapView mMapView;
私有GoogleMap mMap;
@Override
public查看onCreateView(LayoutInflater inflater,
ViewGroup容器,
Bundled savedInstanceState){
查看视图= inflater.inflate(R.layout .basic_demo,null);
// view.setBackgroundColor(0x00000000);
mMapView =(MapView)view.findViewById(R.id.map);
container.requestTransparentRegion(mMapView);
mMapView.onCreate(savedInstanceState);
返回视图;
$ / code $ / pre
这里是我在家里的活动, @Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.home_screen,new BasicMapActivity())
.commit();
getSlidingMenu()。setSecondaryMenu(
getLayoutInflater()。inflate(R.layout.resq_events_frame,null));
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.resq_events_screen,new EventsFragment())
.commit();
//设置背后视图
setBehindContentView(R.layout.activity_settings_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_screen,new SettingsFragment())
.commit();
//自定义SlidingMenu
getSlidingMenu()。setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}
我的XML文件看起来像这样
<?xml version =1.0encoding =utf-8?>
< FrameLayout xmlns:android =http://schemas.android.com/apk/res/android
android:id =@ + id / home_screen
android:layout_width =match_parent
android:layout_height =match_parent>
< / FrameLayout>
如何克服这个问题?
在这里如何看图像。
解决方案问题归因于GoogleMap,您必须添加 map:zOrderOnTop =true添加到您的XML地图布局中,例如
< LinearLayout xmlns:android = http://schemas.android.com/apk/res/android
android:layout_width =fill_parent
android:layout_height =fill_parent>
<片段
android:name =com.google.android.gms.maps.SupportMapFragment
xmlns:map =http://schemas.android.com / apk / res-auto
android:id =@ + id / map
android:layout_width =match_parent
android:layout_height =match_parent
map: zOrderOnTop =true/>
< / LinearLayout>
I'm using sliding menu for Android here is the link, when I slide on rendered map fragment, the sliding menu goes blank.
Here is my map fragment code.
public class BasicMapActivity extends SherlockFragment {
private MapView mMapView;
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.basic_demo, null);
// view.setBackgroundColor(0x00000000);
mMapView = (MapView) view.findViewById(R.id.map);
container.requestTransparentRegion(mMapView);
mMapView.onCreate(savedInstanceState);
return view;
}
}
Here is my home activity where in i render map.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.home_screen, new BasicMapActivity())
.commit();
getSlidingMenu().setSecondaryMenu(
getLayoutInflater().inflate(R.layout.resq_events_frame, null));
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.resq_events_screen, new EventsFragment())
.commit();
// set the Behind View
setBehindContentView(R.layout.activity_settings_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_screen, new SettingsFragment())
.commit();
// customize the SlidingMenu
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}
My XML file looks like this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_screen"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
How to overcome by this issue?
Here how the image looks.
解决方案 The issue is due to GoogleMap, you have to add this map:zOrderOnTop="true" to your XML map layout, like
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:zOrderOnTop="true" />
</LinearLayout>
这篇关于将Google地图渲染为片段时的黑色视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!