gpt4 book ai didi

android - 图像按钮在谷歌地图 v2 中的 InfoWindowAdapter 中不起作用

转载 作者:太空狗 更新时间:2023-10-29 16:39:29 25 4
gpt4 key购买 nike

我正在尝试在我的标记信息中添加一些图像按钮。尽管按钮已添加到 View 中,但我无法点击它们。当我尝试单击它时,它会单击整个 View 。我的代码我们在下面给出。

主 Activity .java

private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RelativeLayout base;
base = (RelativeLayout) findViewById(R.id.base);
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
try {
initilizeMap(); // Loading map
} catch (Exception e) {
Log.d("asdfadfadf", "asdfasdf");
}
googleMap.setMyLocationEnabled(true);
//googleMap.clear();
IconGenerator i = new IconGenerator(getBaseContext());
i.setStyle(IconGenerator.STYLE_BLUE);
Bitmap tt = i.makeIcon("asdf");
LatLng myLocation = new LatLng(22.899171, 89.500186);
Marker myLocMarker = googleMap.addMarker(new MarkerOptions()
.position(myLocation)
.icon(BitmapDescriptorFactory.fromBitmap(tt))
.title("sssss"));
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

@Override
public View getInfoWindow(Marker mk) {
// TODO Auto-generated method stub

return null;
}

@Override
public View getInfoContents(Marker arg0) {
// TODO Auto-generated method stub
ImageButton set,from,favor;
View view = getLayoutInflater().inflate(R.layout.marker_info,null);
set = (ImageButton) view.findViewById(R.id.imageButtonDestination);
from = (ImageButton) view.findViewById(R.id.imageButtonFrom);
favor = (ImageButton) view.findViewById(R.id.imageButtonFavourite);
set.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("sssssssssssssssss", "sssssssssssssssss");
}
});
return view;
}
});
}

/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap(); // check if map is created successfully or not
}
}

@Override
protected void onResume() {
super.onResume();
initilizeMap();
}

}

不知道该怎么办。提前致谢。

最佳答案

您不能向标记的 InfoWindow 添加点击监听器,因为它不是真实 View 。但是从您的布局中呈现的位图。

来自 Google 文档:https://developers.google.com/maps/documentation/android/marker#info_windows

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

关于android - 图像按钮在谷歌地图 v2 中的 InfoWindowAdapter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20422920/

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