每当我单击一个标记时,所有视图都会膨胀,但是图像只是停留在占位符上,并且图像不会加载。如果我第二次单击,则图像已正确加载。这是我的适配器代码:
public class CustomWindowAdapter implements GoogleMap.InfoWindowAdapter {
CustomWindowAdapter.Callback mCallback;
Context context;
interface Callback {
Attraction getDictionary(String key);
}
LayoutInflater mInflater;
CustomWindowAdapter(LayoutInflater i, CustomWindowAdapter.Callback callback) {mInflater = i;
mCallback = callback;}
@Override
public View getInfoWindow(final Marker marker) {
String name = marker.getTitle();
Attraction attraction = mCallback.getDictionary(name);
String imageUrl = attraction.getImage().getUrl();
View v = mInflater.inflate(R.layout.custom_info_window, null);
context = v.getContext();
// Populate fields
TextView title = (TextView) v.findViewById(R.id.tvInfoName);
title.setText(name);
ImageView image = (ImageView) v.findViewById(R.id.ivInfo);
TextView description = (TextView) v.findViewById(R.id.tvInfoDescription);
description.setText(marker.getSnippet());
ImageView imageView = v.findViewById(R.id.ivInfo);
if(imageUrl != null)
Glide.with(context).load(imageUrl)
.apply(RequestOptions
.placeholderOf(R.color.placeholderColor)
.circleCrop())
.into(imageView);
// Return info window contents
return v;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
字典就是我如何保存以后要访问的每个位置的信息的方法。