我在我的应用程序中使用谷歌地图V2,当我将方向更改为横向(或者基本上更改方向)时,onMapClick方法不响应,即使方向再次更改也不响应。我知道我可以通过设置configChange:orientation|screenSize来避免这个奇怪的bug,但是当orientaiton改变时,我对话的布局不会从布局-纵向更改为布局-横向。这一切都在一个活动中。有没有人遇到过这个问题?地图有什么问题?我不明白问题出在哪里,为什么监听器应该取消注册。我在onCreateMethod中注册:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);
DisplayMetrics dm = getResources().getDisplayMetrics();
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
FontUtils.setCustomFont(this, (ViewGroup) getWindow().getDecorView());
RelativeLayout topBar = (RelativeLayout) findViewById(R.id.topBar);
LinearLayout placeTextLayout = (LinearLayout)topBar
.findViewById(R.id.placeTextLayout);
placeTextView = (TextView) placeTextLayout.findViewById(R.id.placeText);
sharedPrefs = getSharedPreferences
(SkyConstants.PREFS_NAME,Context.MODE_PRIVATE);
String place = sharedPrefs.getString
(SkyConstants.PREF_LOCATION_ID,SkyConstants.PREF_LOCATION_DEFAULT);
dateTextView = (TextView) topBar.findViewById(R.id.dateText);
daysTextView = (TextView) topBar.findViewById(R.id.timeText);
updateTopBar();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded()
{
if (mMap == null)
{
mMap = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
if (mMap != null)
{
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.setOnMapClickListener(new OnMapClickListener()
{
@Override
public void onMapClick(LatLng point)
{
//do something
}
});
}
}发布于 2013-03-30 19:02:24
在onCreate()方法中将map设置为null很有帮助,因为我需要处理系统对方向的更改。所以我首先设置了mMap=null,然后设置了映射。
发布于 2013-03-22 00:36:43
这是由于为方向创建了视图,如果您处于纵向模式,并且更改为横向,则会再次创建视图,并且您需要再次设置onClickListener。
如果您在横向模式下开始此活动,也会发生同样的情况。
https://stackoverflow.com/questions/15552315
复制相似问题