gpt4 book ai didi

android - Google Maps v2 - onclick 监听器在方向更改后不响应

转载 作者:行者123 更新时间:2023-11-30 03:42:14 24 4
gpt4 key购买 nike

我在我的应用程序中使用 Google Maps V2,当我将方向更改为横向(或基本上更改方向)时,onMapClick 方法不响应并且即使在方向再次更改后也不会响应。我知道我可以通过设置 configChange:orientation|screenSize 来避免这个奇怪的错误,但是当方向改变时,我的对话布局不会将它们的布局从纵向布局更改为横向布局。这一切都在一项 Activity 中。有没有人遇到过这个问题? map 有什么问题?我不明白问题出在哪里,为什么应该取消注册听众。我在 onCreateMethod 中注册它: @覆盖 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

}

});
}
}

最佳答案

这是由于为方向创建了 View ,如果您处于纵向模式,然后更改为横向,它会再次创建 View ,您需要再次设置 onClickListener。

如果您以横向模式启动 Activity,则会发生同样的情况。

关于android - Google Maps v2 - onclick 监听器在方向更改后不响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15552315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com