gpt4 book ai didi

android - 将 Glide 与 GoogleMap.InfoWindowAdapter 结合使用

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

我正在尝试使用 Glide 将自定义图像加载到 Google map 信息窗口。我将 Activity 上下文传递给适配器(请参阅下面的代码)。但我既没有看到图像也没有看到错误。

我做错了什么?

class GuideMapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

private final View mWindow;
private final View mContents;
private HashMap<Marker, MapPoint> mMarkers;
private Context mContext;

GuideMapInfoWindowAdapter(Context context, HashMap<Marker, MapPoint> markerMapPointHashMap) {
mWindow = getLayoutInflater().inflate(R.layout.guide_map_custom_info_window, null);
mContents = getLayoutInflater().inflate(R.layout.guide_map_custom_info_content, null);
mMarkers = markerMapPointHashMap;
mContext = context;
}

@Override
public View getInfoWindow(Marker marker) {
render(marker, mWindow);
return mWindow;
}

@Override
public View getInfoContents(Marker marker) {
render(marker, mContents);
return mContents;
}

private void render(Marker marker, View view) {
ImageView mImage = (ImageView) view.findViewById(R.id.badge);
MapPoint mPoint = markers.get(marker);
String mUrl = UrlBuilder.guidePhoto(mPoint.getGuideId(), mPoint.getPageId(), 100);
Glide.with(mContext)
.load(mUrl)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mImage);

String title = marker.getTitle();
TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}

String snippet = marker.getSnippet();
TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
}
}

最佳答案

问题是,您正在异步下载图像。在 getInfoContents 中返回 mContents 后,对 imageview 的任何更改都不会反射(reflect)出来。

我已经更新了你的渲染函数,不过还没有测试过。

private void render(Marker marker, View view) {
ImageView mImage = (ImageView) view.findViewById(R.id.badge);
MapPoint mPoint = markers.get(marker);
String mUrl = UrlBuilder.guidePhoto(mPoint.getGuideId(), mPoint.getPageId(), 100);
Bitmap image = Glide.with(mContext)
.load(mUrl)
.asBitmap()
.into(-1,-1)
.get();
mImage.setImageBitmap(image);

String title = marker.getTitle();
TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}

String snippet = marker.getSnippet();
TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
}

关于android - 将 Glide 与 GoogleMap.InfoWindowAdapter 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33605911/

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