作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在“InfoWindowAdapter”中显示来自 url 的图像 ,我有以下代码,但没有显示图像
....
mMap = getMap();
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
...
@Override
public View getInfoContents(Marker marker) {
View v = getActivity().getLayoutInflater().inflate(
R.layout.info_window_layout, null);
String image_url = "http://api.androidhive.info/images/sample.jpg";
new DownloadImageTask(imgEquipo).execute(image_url);
return v;
}
});
调用AsyncTask获取图像
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
} }
}
感谢您的帮助。
最佳答案
这是行不通的,因为在您获取图像之前返回了 View ,并且它们不同步。
看看这个方法:
诀窍是在获取图像后更新 InfoWindow。
关于android - 如何从 url 图像到 InfoWindowAdapter android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15346254/
我是一名优秀的程序员,十分优秀!